即使if语句中发生警报,if语句中的jQuery代码仍未运行 [英] jQuery code in if statement not running even though alert in if statement happens
问题描述
我有一个if语句,里面有两个警告以及一个变量赋值。当条件满足时,所有这三件事都会发生。
I have an if statement and there are two alerts inside it as well as a variable assignment. All three of these things happen when the condition is met.
但是当我将jQuery代码添加到if语句的套件中时,jQuery代码就不会发生。
But when I add jQuery code to the if statement's suite, that jQuery code doesn't happen.
我如何获得 $('#tabViewWindow')。animate({left:'100%'});
在我的条件下发生?
我尝试将上述代码发生的条件发生在是:
否则if(obj.dx> 0&& obj。$ el.offset()。left> = $(window).width()* 0.6 ){
这是我的所有代码:
$('#tabViewWindow').pep({
axis: 'x',
useCSSTranslation: false,
drag: function (ev, obj) {
if (obj.dx < 0 && obj.$el.offset().left > $(window).width() * 0.8) {
//block left-drag when drag is left and object is 80% off screen
obj.velocityQueue = new Array(5);
return false;
} else if (obj.dx > 0 && obj.$el.offset().left >= $(window).width() * 0.6) {
//drag direction is right and object is 60% off screen
alert("slide right here");
open = false;
alert("open is: " + open);
} else if (obj.dx > 0) {
open = true;
}
handleOpacity(ev, obj)
},
});
function handleOpacity(ev, obj) {
var opacity = 1 - (parseInt(obj.$el.css('left')) / $(window).width());
obj.$el.css('opacity', opacity);
}
推荐答案
尝试添加 position:absolute;
或 position:relative;
(至少初始左
和 top
属性)到 #tabViewWindow
的样式。 left
属性仅适用于具有该属性的元素。或者,如果您想要保留元素静态位置,您可以设置动画 margin-left
属性:
Try to add position:absolute;
or position:relative;
(and at least initial left
and top
properties) to styles of #tabViewWindow
. left
property only applies to elements with that properties. Or if you want to leave position of element static you can animate margin-left
property:
$('#tabViewWindow').animate({'margin-left' : '100%'}, 500);
这篇关于即使if语句中发生警报,if语句中的jQuery代码仍未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!