我已经创建了DIV.cb-切换,当用户在这个div上徘徊时,它会移动到Orange,当他们悬停在这个div上时,它会回复到灰色,当用户单击这个div时,它会显示为蓝色,告诉用户它已经被选中了。所以当它没有被选中时,它有鼠标鼠标动画,但是当它被选中时,我想解开鼠标鼠标,我不希望鼠标悬停事件在被选中时工作,只有当它没有被选中时。做我想做的事情最好的方法是什么?我想出了下面的代码,但我很确定这是一种很糟糕的方法,我不知道该怎么做。非常感谢你的帮助。
我的代码:
$('.cb-toggle').toggle(function() {
$(this).animate({"background":"blue", "color":"#fff;"});
$(".cb-toggle").unbind("click.myfadee");
}, function() {
$(this).animate({"background":"gray", "color":"#fff;"});
$('.cb-toggle').trigger('mouseenter');
});
});和我称之为bind:
$(".cb-toggle").bind("click.myfadee", function(){
$(".cb-toggle").mouseenter(function() {
$(this).animate({"background":"orange", "color":"#fff;"});
}).mouseleave(function() {
$(this).animate({"background":"gray", "color":"#fff;"});
});
});我需要保留背景颜色动画,而且我不使用jquery,因此不能在类之间动画。
发布于 2010-09-21 02:18:44
你知道,只要有一点CSS,这是很容易实现的。
CSS
.cb-toggle {
background-color: gray;
color: #fff;
}
.cb-toggle:hover {
background-color: orange;
}
.cb-toggle.selected {
background-color: blue;
}HTML
<a href="#" class="cb-toggle">Toggle This</a>jQuery
$('.cb-toggle').click(function() {
$(this).toggleClass('selected');
});这只是一个例子,你可以扩展它来做你的动画。你可能也想要这个链接
https://stackoverflow.com/questions/3756798
复制相似问题