我需要一个jQuery脚本,看看是否有任何元素有一个特定的类,并做一个像改变位置的动作。
这是办法,但我认为这行不通。
$("a.contact").toggle(function() {
$("#contact").animate({
right: '0'
}, 2000);
if ($("#about").hasClass("opened")) {
$("#about").animate({
right: -700 + "px"
}, 2000);
}
}, function() {
$("#contact").animate({
right: -700 + "px"
}, 2000);
});
发布于 2010-12-31 02:16:11
首先,您的条件语句中缺少一些括号:
if ($("#about").hasClass("opened")) {
$("#about").animate({right: "-700px"}, 2000);
}
但您也可以将其简化为:
$('#about.opened').animate(...);
如果#about
没有opened
类,它就不会有动画效果。
如果问题出在动画本身,我们需要了解更多关于元素定位的信息(绝对?绝对内部相对父级?父级是否有布局?)
https://stackoverflow.com/questions/4565075
复制相似问题