我以前问过这个问题。但现在我将尝试更具体一点。
当你把鼠标移到一个方框上时,我试着让背景淡入。我已经尝试了两种不同的选择。
选项1: Box1是鼠标滑过的方框,hover1是新的背景。这实际上工作得很好。然而,它加载了acript,这意味着,如果我只是疯狂地将鼠标放在盒子上,即使我的鼠标静止不动,也会无休止地退缩。你有办法阻止它吗?内容是当我将鼠标移到内容框中时会发生变化的文本。这个很好用。
$("#box1").mouseover(function(){
$("#background").switchClass("nohover", "hover1", 500);
$("#content").html(box1);
});
$("#box1").mouseout(function(){
$("#background").switchClass("hover1", "nohover", 150);
$("#content").html(content);
});选项2:在这里,我添加了类hover2,并要求它淡入淡出。但这根本不起作用。有时候,当我把鼠标从盒子里拿出来的时候,它甚至把边上的所有东西都移走了。
$("#box2").mouseover(function(){
$("#background").addClass("hover2").fadeIn("slow")
$("#content").html(box3);
});
$("#box2").mouseout(function(){
$("#background").removeClass("hover2").fadeOut("slow")
$("#content").html(content);
});我使用jquery ui。我真的希望有人能帮助我!
发布于 2012-05-10 19:51:49
您还可以尝试在标记/CSS中进行一些小的更改。
HTML:
<div id="box">
<div id="background"></div>
<div id="content"></div>
</div>CSS:
#box {
position: relative;
/* ... */
}
#background {
position: absolute;
display: none;
top: 0;
left: 0;
width: inherit;
height: inherit;
background-image: url(...);
z-index: -1;
}JavaScript:
$("#box").hover(function() {
$("#background").fadeIn();
}, function() {
$("#background").stop().fadeOut();
});发布于 2012-05-10 19:49:10
尝试添加一个变量,以便仅当该变量具有特定值时才控制效果的执行。并在执行效果时修改其值。
如下所示:
var goeft = 0;
$("#box1").mouseover(function(){
if(goeft == 0) {
$("#background").switchClass("nohover", "hover1", 500);
$("#content").html(box1);
goeft = 1;
}
});
$("#box1").mouseout(function(){
$("#background").switchClass("hover1", "nohover", 150);
$("#content").html(content);
// sets its value back to 0 if you want the next mouseover execute the effect again
goeft = 0;
});https://stackoverflow.com/questions/10533130
复制相似问题