我有一个克隆的元素,我想要它,所以如果我添加一个类到其中一个它检查主动删除是,并将其添加到此并转换为其他。这里就是我的工作:将类添加到多个元素
$(document).ready(function() {
$("li").click(function(){
/*Here I want to add something like var active = $(.clonedelement + this, this)
but that does probably not makes sense, so what should i do? */
var active = $(this)
// If this isn't already active
if (!$(this).hasClass("active")) {
// Remove the class from anything that is active
$("li.active").removeClass("active");
// And make this active
active.addClass("active");
}
});
});
眼下,它消除了当前的活动从两个,不也只添加类之一。
我做了它的jsfiddle http://jsfiddle.net/pintu31/8BxuE/
function UpdateTableHeaders() {
$(".persist-area").each(function() {
var el = $(this),
offset = el.offset(),
scrollTop = $(window).scrollTop(),
Header = $("#headerny", this)
if ((scrollTop > offset.top) && (scrollTop < offset.top + el.height())) {
Header.addClass("floatingHeader");
} else {
Header.removeClass("floatingHeader");
};
});
}
// DOM Ready
$(function() {
$(window)
.scroll(UpdateTableHeaders)
.trigger("scroll");
});
它仍然不能将它添加到其他的元素之一;现场看到主要的导航这里的http:// richardhedberg .com/portfoliony/index.html –
@RichardHedberg,检查更新后的代码是否需要th是什么? –
谢谢,但不是真的我在找什么。我会试着解释一下,我有一个带有li的标题,当向下滚动时它会复制并隐藏第一个。我需要活动状态在他们之间转移。我会将克隆脚本添加到初始文章中,以便您自己查看。 –