悬停保持活动状态,直到鼠标移到另一个悬停对象上
Hover stays active, until mouseover another hoverable object
假设我有三个方框。每一个都可以悬停,当悬停时,它们的背景颜色将变为红色。
我想让它即使当你的鼠标离开盒子(并且没有触摸到另一个可以悬停的盒子),它保持活动
这是一个JSFiddle: http://jsfiddle.net/LvtWB/2/
我希望能够悬停在其中一个,把它变成红色,当鼠标进入空白区域时,背景变化保持活跃。当鼠标进入另一个方框时,它才能回到正常状态。
我怎样才能做到这一点?
jQuery:$(document).ready(function(){
$('.box').eq(1).animate({
backgroundColor: "red"
}, 800);
$('.box').hover(function(){
$('.box').stop().animate({
backgroundColor: "green"
}, 800);
$(this).stop().animate({
backgroundColor: "red"
}, 800);
},
function(){
$(this).stop().animate({
backgroundColor: "green"
}, 800);
});
});
尝试删除hover的第二个函数调用:
$('.box').eq(1).animate({
backgroundColor: "red"
}, 800);
$('.box').hover(function () {
$('.box').stop().animate({
backgroundColor: "green"
}, 800);
$(this).stop().animate({
backgroundColor: "red"
}, 800);
})
<<p> jsFiddle例子/strong> 或者不使用悬停(因为你不使用第二部分):
$('.box').eq(1).animate({
backgroundColor: "red"
}, 800);
$('.box').mouseenter(function(){
$('.box').stop().animate({
backgroundColor: "green"
}, 800);
$(this).stop().animate({
backgroundColor: "red"
}, 800);
});
<<p> jsFiddle例子/strong> 您想使用mouseenter
事件而不是hover
事件。
相关文章:
- 如何在鼠标悬停时在另一个图像上滑动图像.
- 将鼠标悬停在Angular JS中的一个元素上,并将Class添加到另一个元素中
- 如何激活下拉菜单:在一个元素上单击768px宽度下方,在另一个元素上将鼠标悬停在768px上方
- 当鼠标也在触摸另一个元素时,d3.js鼠标悬停事件未被触发
- 在单击按钮时激活按钮的悬停状态,直到单击另一个按钮(Javascript/JQuery)
- 将鼠标悬停在一个元素上,可以将类添加到另一个元素中
- 在悬停时显示一个DIV,在悬停的另一个DIV.使用CSS
- jQuery悬停淡出p个标签,再淡出另一个标签
- 将鼠标悬停在按钮上会导致另一个按钮悬停在上面
- 可拖动元素在悬停在另一个'It’s draggable
- 使用悬停(javascript)将图像加载到另一个图像上
- 如何在通过 Angular 将鼠标悬停在另一个元素上时添加和删除一个元素的类
- 将鼠标悬停在另一个图像上时,将图像替换为另一个图像
- 元素将鼠标悬停在另一个元素上
- 另一个jQuery滑块在悬停时暂停
- jQuery - 是否可以将鼠标悬停到另一个元素
- 将鼠标悬停在某个班级时激活另一个班级
- 在悬停另一个ID时更改ID img src
- 当悬停另一个图像时隐藏图像
- 悬停另一个项目时关闭菜单