繁体   English   中英

当我用鼠标离开元素但用鼠标进入弹出框时,如何隐藏弹出框?

[英]How do I make the Popover hide when I mouseleave the element but mouseenter the popover?

这是弹出窗口的HTML,用于当有人将鼠标悬停在个人资料缩略图上方时显示用户个人资料的摘要。

                      <div class="user-avatar" style="background-image: url({{          $chat->from->small_avatar }}); " data-container="body" data-toggle="popover" data-placement="right" data-html="true" data-content="<div class='group-chat-popover'>
                      <div class='popover-header'>
                        <div class='chat-avatar' style='background-image:url({{ $chat->from->small_avatar }})'></div>
                        <div class='header-description'>
                          <p class='user-name'>{{ $chat->from->full_name }}</p>
                          <p class='user-bio'>{{ $chat->from->about }}</p>
                        </div>
                      </div>
                      <div class='user-activity'>
                        <div class='activity'>
                          <p class='activity-category'>Reputation</p>
                            <p class='activity-count'>{{ $chat->from->total_points }}</p></div>
                        <div class='activity'>
                          <p class='activity-category'>Submissions</p>
                            <p class='activity-count'>{{ $chat->from->approved_tutorials->count() }}</p></div>
                        <div class='activity'>
                          <p class='activity-category'>Upvotes</p>
                            <p class='activity-count'>{{ $chat->from->votes->count() }}</p></div>
                      </div>
                      <div class='popover-footer'>
                        <a href='{{ $chat->from->profile_link }}' class='btn btn-sm btn-select'>Open profile</a>
                        <a href='{{ $chat->from->chat_link }}' class='btn btn-sm btn-primary'>Private Chat</a>
                        </div>
                    </div>">
                    </div>

这是我编写的触发和关闭弹出窗口的代码。 我也在这里使用引导程序弹出窗口。

            var timer;
            $(".user-avatar").popover({
                trigger: "manual",
                animation: false
            })
                .on("mouseenter", function(){
                var self = $(this);
                timer = setTimeout(function(){
                    self.popover("show");
                }, 1000);
            })
                .on("mouseleave", function () {
                clearTimeout(timer);

                $(".popover").on("mouseleave", function () {
                    $(this).popover('hide');
            });
                setTimeout(function () {
                    if (!$(".popover:hover").length) {
                        $(this).popover("hide");
                    }
                }, 30);
            });

问题是,当我用鼠标输入缩略图时,我无法隐藏弹出窗口,而直接用鼠标留下缩略图(没有鼠标留下弹出窗口)。

我想要以下行为:

当我用鼠标输入缩略图时会显示弹出窗口。 当我用鼠标点击弹出窗口时,弹出窗口保持打开状态。 当我用鼠标离开弹出窗口时,弹出窗口会隐藏。 当我用鼠标离开缩略图时,弹出窗口会隐藏(不显示弹出窗口)。

我无法达到最后一点!

您可能应该在鼠标离开元素时设置一个计时器,并在鼠标进入弹出框时清除它。 像这样:

        var timer;
        $(".user-avatar").popover({
            trigger: "manual",
            animation: false
        }).on("mouseenter", function(){
            $(this).popover("show");
        }).on("mouseleave", function () {
            var self = $(this);
            timer = setTimeout(function(){ // You may want to keep a reference to the time of each element.
                self.popover("hide");
            }, 1000);
        });

        $(".popover").on("mouseenter", function(){
            clearTimer(timer);
        }).on("mouseleave", function () {
            $(this).popover("hide"); // I'm not sure this will work, you may have to keep a reference to the element that owns this popover.
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM