首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >页面加载和悬停时出现类似Coda的弹出气泡?- jQuery

问页面加载和悬停时出现类似Coda的弹出气泡?- jQuery
EN

Stack Overflow用户
提问于 2012-06-17 22:24:07
回答 1查看 856关注 0票数 1

我在我的网站上使用了类似Coda的气泡:http://jqueryfordesigners.com/coda-popup-bubbles/

我想知道是否有可能在页面加载后直接显示气泡,让它停留几秒钟,然后再次隐藏它,同时仍然能够在您将鼠标悬停在触发器上时显示它?

下面是我的代码:

代码语言:javascript
复制
$(document).ready(function(){

    $(function() {
    $('.bar').each(function() {
        // options
        var distance = 5;
        var time = 250;
        var hideDelay = 1000;

        var hideDelayTimer = null;

        // tracker
        var beingShown = false;
        var shown = false;

        var trigger = $('.trigger', this);
        var popup = $('.popup', this).css('opacity', 0);

        // set the mouseover and mouseout on both element
        $([trigger.get(0), popup.get(0)]).mouseover(function() {
            // stops the hide event if we move from the trigger to the popup element
            if (hideDelayTimer) clearTimeout(hideDelayTimer);

            // don't trigger the animation again if we're being shown, or already visible
            if (beingShown || shown) {
                return;
            } else {
                beingShown = true;

                // reset position of popup box
                popup.css({
                    top: 410,
                    left: 164,
                    display: 'block' // brings the popup back in to view
                })

                // (we're using chaining on the popup) now animate it's opacity and position
                .animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    // once the animation is complete, set the tracker variables
                    beingShown = false;
                    shown = true;
                });
            }
        }).mouseout(function() {
            // reset the timer if we get fired again - avoids double animations
            if (hideDelayTimer) clearTimeout(hideDelayTimer);

            // store the timer so that it can be cleared in the mouseover if required
            hideDelayTimer = setTimeout(function() {
                hideDelayTimer = null;
                popup.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function() {
                    // once the animate is complete, set the tracker variables
                    shown = false;
                    // hide the popup entirely after the effect (opacity alone doesn't do the job)
                    popup.css('display', 'none');
                });
            }, hideDelay);
        });
    });
});

});

我非常感谢你的帮助,如果这是非常简单和明显的,我向你道歉!我是jQuery的新手。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-01 18:10:59

这将帮助您留下来并隐藏弹出窗口。

代码语言:javascript
复制
        label.addEventListener("mouseover",function(e)
          {                 
                   if(hideDelayTimer)
                   clearTimeout(hideDelayTimer);
                   label.appendChild(popup);

          });

         label.addEventListener("mouseout",function()
           {
                  hideDelayTimer=setTimeout(function()
                 {
                      label.removeChild(popup);

                 },hideDelay);

           });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11072008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档