为什么变量的pageX是未定义的

时间:2017-06-09 16:35:29

标签: javascript

我不知道为什么mMove未定义。这是JS的样本

function quotoesMove(mMove){
    var quotes = document.getElementById("quotes");
   var  mMove = quotes.pageX; 
    console.log(mMove);
}
function quotesClick(){
 var quotes = document.getElementById("quotes");
    var mClickY = quotes.pageX;
    var mMove;
    quotoesMove(mMove);
    console.log(mMove + "something")
    var mouseRoad = mMove - mClickY;

    if(mouseRoad>0){
        quotes.style.marginRightright = mouseRoad + "px";

    }
    else{
        quotes.style.marginLeft = mouseRoad*(-1) + "px";
    }
}
 document.getElementById("quotes").addEventListener("mousemove", quotoesMove);
 document.getElementById("quotes").addEventListener("click", quotesClick);

以下是codepen https://codepen.io/anon/pen/bREMYQ

上html,css和js的链接

0 个答案:

没有答案