我需要一个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);
});
首先,条件句中缺少一些括号:
if ($("#about").hasClass("opened")) {
$("#about").animate({right: "-700px"}, 2000);
}
但您也可以将其简化为:
$('#about.opened').animate(...);
如果#about
没有opened
类,它将不会动画。
如果问题出在动画本身,我们需要更多地了解元素的定位(绝对?绝对在相对父级内部?父级有布局吗?)