我不知道为什么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的链接