[英]jQuery mouseover / mouseout show/hide div
The blue square, shown in the picture, is buttonShowHidePicture
(a button) and the red square is currentPictures
(a div
). 如图所示,蓝色正方形是
buttonShowHidePicture
(一个按钮),红色正方形是currentPictures
(一个div
)。
Desired functionality : when I move the mouse over the button I want the div to appear, then I want to be able to move the mouse over the div and click on one of the pictures. 所需的功能 :当我将鼠标移到该按钮上时,我希望显示div,然后希望将鼠标移到div上并单击其中一张图片。 When the cursors it's out of the div the div must disappear.
当光标移到div之外时,div必须消失。
Issue I'm facing : however, the code below works as long as I don't scroll down: when I move the cursor on the pictures on the bottom the div scrolls back up because it triggers the hide/show all the time. 我面临的问题 :但是,只要不向下滚动,下面的代码就可以工作:当我将光标移到底部图片上时,div会向上滚动,因为它始终会触发隐藏/显示。 How can I fix this?
我怎样才能解决这个问题?
This is my jQuery: 这是我的jQuery:
$('#buttonShowHidePicture, #currentPictures').mouseover(function () {
$('#currentPictures').show();
});
$('#currentPictures, #buttonShowHidePicture').mouseout(function () {
$('#currentPictures').hide();
});
try something like this 尝试这样的事情
$(document).ready(function () {
$('li').mouseover(function (e) {
e.stopPropagation();
$('>.actions', this).css('visibility', 'visible')
});
$('li').mouseout(function (e) {
e.stopPropagation();
$('.actions').css('visibility', 'hidden')
})
});
for more https://www.sitepoint.com/community/t/show-hide-a-div-with-mouseover-and-mouseout-on-li/6441/2 有关更多https://www.sitepoint.com/community/t/show-hide-a-div-with-mouseover-and-mouseout-on-li/6441/2
Use mouseleave event instead mouseout. 使用mouseleave事件代替mouseout。 Because hide event is also firing on your images inside div.
因为hide事件也在div中的图像上触发。
$('#currentPictures, #buttonShowHidePicture').mouseleave(function () {
$('#currentPictures').hide();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.