Why is the object not moving on clicking the button?

后端 未结 3 1024
我在风中等你
我在风中等你 2021-01-28 17:27

The object is not moving on clicking the button. Why is it so?

<
3条回答
  •  心在旅途
    2021-01-28 17:52

    You should not detach style object from DOM element. Also the name of your function conflicts with native Element.animate function, name your function diffrently.

    This should work:

    function animateX() {
      var object = document.getElementById('object');
      var x = 100;
      object.style.left = x + 'px';
    }
    #object {
      position: absolute;
      top: 50px;
      right: 20px;
      left: 20px;
      height: 40px;
      width: 80px;
      background-color: green;
    }

提交回复
热议问题