修复Popup以顺利抬起

Fix Popup to lift up smoothly

本文关键字:Popup 修复      更新时间:2023-09-26

我创建了一个弹出对话框,当用户滚动页面时,该对话框在左下角向上。你可以在这里看到它的直播-http://uposonghar.com/jobs/odesk/daniel/new/

我的问题是它第一次举起时不顺利,然后就可以了。任何人都请提出任何解决方案。需要让它顺利举起。

我的代码

<div id="scrolltriggered" style="width: 310px; left: 10px; bottom: 10px;">
<div id="inscroll">
    <a href="#close" id="closebox">x</a><a href="http://www.google.com" target="_blank"><img src="images/buyersguide.png" alt="Free Resources" height="235" width="310">
     </a>
</div>
</div>

<script type="text/javascript"> 
var stb = {
hascolsed: false,
cookieLife: 7,
triggerHeight: 30,
stbElement: ""
}; 
</script>

Javascript代码-

if (typeof stb === "undefined")
var stb = {};
jQuery(document).ready(function () {
jQuery("#closebox").click(function () {
    jQuery('#scrolltriggered').stop(true, true).animate({ 'bottom':'-210px' }, 700, function () {
        jQuery('#scrolltriggered').hide();
        stb.hascolsed = true;
        jQuery.cookie('nopopup', 'true', { expires: stb.cookieLife, path: '/' });
    });
    return false;
});
stb.windowheight = jQuery(window).height();
stb.totalheight = jQuery(document).height();
stb.boxOffset = '';
if (stb.stbElement != '') {
    stb.boxOffset = jQuery(stb.stbElement).offset().top;
}
jQuery(window).resize(function () {
    stb.windowheight = jQuery(window).height();
    stb.totalheight = jQuery(document).height();
});
jQuery(window).scroll(function () {
    stb.y = jQuery(window).scrollTop();
    stb.boxHeight = jQuery('#scrolltriggered').outerHeight();
    stb.scrolled = parseInt((stb.y + stb.windowheight) / stb.totalheight * 100);

    if (stb.showBox(stb.scrolled, stb.triggerHeight, stb.y) && jQuery('#scrolltriggered').is(":hidden") && stb.hascolsed != true) {
        jQuery('#scrolltriggered').show();
        jQuery('#scrolltriggered').stop(true, true).animate({ 'bottom':'10px' }, 700, function () {
        });
    }
    else if (!stb.showBox(stb.scrolled, stb.triggerHeight, stb.y) && jQuery('#scrolltriggered').is(":visible") && jQuery('#scrolltriggered:animated').length < 1) {
        jQuery('#scrolltriggered').stop(true, true).animate({ 'bottom':-stb.boxHeight }, 700, function () {
            jQuery('#scrolltriggered').hide();
        });
    }
});
jQuery('#stbContactForm').submit(function (e) {
    e.preventDefault();
    stb.data = jQuery('#stbContactForm').serialize();
    jQuery.ajax({
        url:stbAjax.ajaxurl,
        data:{
            action:'stb_form_process',
            stbNonce:stbAjax.stbNonce,
            data:stb.data
        },
        dataType:'html',
        type:'post'
    }).done(function (data) {
            jQuery('#stbMsgArea').html(data).show('fast');
        });
    return false;
});
});
(function(stb_helpers) {
stb_helpers.showBox = function(scrolled, triggerHeight, y) {
    if (stb.isMobile()) return false;
    if (stb.stbElement == '') {
        if (scrolled >= triggerHeight) {
            return true;
        }
    }
    else {
        if (stb.boxOffset < (stb.windowheight + y)) {
            return true;
        }
    }
    return false;
};
stb_helpers.isMobile = function(){
    if (navigator.userAgent.match(/Android/i)
        || navigator.userAgent.match(/webOS/i)
        || navigator.userAgent.match(/iPhone/i)
        || navigator.userAgent.match(/iPod/i)
        || navigator.userAgent.match(/BlackBerry/i)
        ) {
        return true;
    }
    else return false;
}
})(stb);

我认为您需要css更改,请将以下内容复制粘贴到您的aspx 中

<div style="width: 310px; left: 10px; bottom: -225px; display: none;" id="scrolltriggered">

希望它能帮助

您所需要做的就是在文档中添加以下行作为第一行

$("#scrolltriggered").css({bottom: -235});

这将确保弹出窗口向下滚动235像素。如果您需要它进行可变滚动,请使用jquery选择器添加Elements高度。

查看Fiddle Here