如何解决这个重叠的悬停问题 [英] How to solve this overlapping hover issue

查看:49
本文介绍了如何解决这个重叠的悬停问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设置一个悬停按钮,当悬停时可以显示弹出图像,悬停时删除弹出图像.我的问题是,当我将鼠标悬停在按钮上时,弹出图像会弹出并覆盖按钮,因此即使光标仍在按钮上,它也会触发悬停事件并删除弹出图像.我该如何解决?

I need to setup a hover button that can show a popup image when hovered and remove the popup image when hover out. My problem is that when I hover the button, the popup image pops and covers the button so it fires the hoverout event and remove the popup image even though the cursor is still on the button. How can I resolve this?

 $('.test').hover(function(){           
            imageId=$(this).next().attr('id');
            $('#div-' + imageId).show(150);
        },function (){
            $('#div-' + imageId).hide(150);
        })

推荐答案

我想弹出式图像不能完全覆盖缩略图(否则这很简单:只需在弹出式图像上触发mouselave事件).然后,这是气泡和菜单的常见问题.如果弹出窗口包含其他鼠标悬停敏感区域,您也会遇到类似的问题.

I'd suppose the popup image doesn't cover entirely the thumbnail (or this would be trivial : simply fire the mouselave event on the popup image). Then this is a frequent problem with bubbles and menu. You have similar problems if the popup contains other mousehover sensitive areas.

您可以在拇指和弹出窗口上注册mouseleave事件,并在接收事件时检查鼠标是否仍在目标上.

You can register mouseleave events both on the thumb and the popup, and check for both if the mouse is still on target when you receive the event.

您可以使用此功能:

// event is an event (usually the mouseleave)
// o is a jquery object
bubbling.eventIsOver = function(event, o) {
    if ((!o) || o==null) return false;
    var pos = o.offset();
    var ex = event.pageX;
    var ey = event.pageY;
    if (
        ex>=pos.left
        && ex<=pos.left+o.width()
        && ey>=pos.top
        && ey<=pos.top+o.height()
    ) {
        return true;
    }
    return false;
};

如果返回true,则鼠标仍悬停在弹出图像或缩略图上,因此不应关闭弹出窗口.

If it returns true, the mouse is still hover the popup image or the thumbnail so the popup shouldn't be closed.

这篇关于如何解决这个重叠的悬停问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆