比较鼠标点击的X坐标与div的当前位置(Javascript)

时间:2016-02-21 23:57:21

标签: javascript html css velocity.js

我没有使用Javascript,但是根据以前的编程经验,我只是有点迷失为什么总是在下面调用else语句:

function moveDiv(event) {
  var x = event.clientX;
  var $div = $("div");  // Used for velocity called in head of html
  var currentPos = document.getElementById("div").style.left; // parse current position in div (set inline)

  if (currentPos > x) {
    $div.velocity({rotateZ:0, left:x+"px"},2000, "ease-in-out");
    alert("CurrentPos is greater than x");
  } 
  else {
    $div.velocity({rotateZ:0, left:x+"px"},100, "ease-in-out");  // Always called
  }
}

0 个答案:

没有答案