我试图在jquery事件中使用if语句,但它不是worknig。这是我的密码:
$(".carousel").swipeleft(function(){
rightPos += 242;
$(this).animate({ "right": rightPos }, swipeSpeed);
var currentRightPos = $(".carousel").css("right");
alert(currentRightPos);
if(currentRightPos > 500){
alert("Its 500");
};
});我不知道发生了什么事。如果语句即使在单击事件中也不能工作。滑动事件也可以正常工作。alert(currentRightPos);也很好,但只有在语句不工作的情况下才能工作。我已经阅读了5-6个问题的堆叠溢出,但没有任何帮助。如果您需要更多的信息,请评论。谢谢。
发布于 2015-07-08 12:13:56
$(".carousel").css("right")返回'Npx'。
试着:
var currentRightPos = parseInt($(".carousel").css("right").replace(/px/, ''));发布于 2015-07-08 12:23:20
应该是这样的。
$(".carousel").click(function(){
var rightPos = "+=242";
var swipeSpeed = 500;
$(this).animate({right:rightPos},swipeSpeed);
var currentRightPos = $(".carousel").css("right");
alert(currentRightPos);
if(currentRightPos > "500"){
alert("Its 500");
};
});https://jsfiddle.net/svejofck/
希望它有帮助:)
https://stackoverflow.com/questions/31292185
复制相似问题