0

为什么这个 Javascript 代码停止向左滑动:-100%?

函数幻灯片左(sellBody){

   var slideLeft = document.getElementById("sellBody");
   var currentLeft = parseFloat(slideLeft.style.left);

   if(slideLeft.style.left<"0"){

       slideLeft.style.transition = "left 1.0s ease 0s";
       slideLeft.style.left = (currentLeft + 100) + "%";
}

}

功能幻灯片(sellBody){

var slideRight = document.getElementById("sellBody");
var currentRight = parseFloat(slideRight.style.left);

if(slideRight.style.left>"-500%"){

    slideRight.style.transition = "left 1.0s ease 0s";
    slideRight.style.left = (currentRight - 100) + "%";
}

}

4

1 回答 1

0
var slideLeft = document.getElementById("sellBody");
var currentLeft = parseFloat(slideLeft.style.left);

if(currentLeft < 0 ){

   slideLeft.style.transition = "left 1.0s ease 0s";
   slideLeft.style.left = (currentLeft + 100) + "%";
}

var slideRight = document.getElementById("sellBody");
var currentRight = parseFloat(slideRight.style.left);

if(currentRight > 500){

slideRight.style.transition = "left 1.0s ease 0s";
slideRight.style.left = (currentRight - 100) + "%";

}

您不能将字符串作为数字进行比较:if(slideLeft.style.left<"0")

于 2013-11-09T12:57:40.517 回答