jquery延迟了电子邮件订阅的滑出

时间:2014-02-10 17:29:22

标签: javascript jquery

我正在尝试制作一个滑动电子邮件订阅框...
我想让它在页面的顶部和底部滑入:

-------------------------------------------------------------------------------
1) 2ms delay after page load = Slide "Out"
2) User scrolls 1/3 from the TOP of the page = Slide "In"
3) User scrolls 1/3 from the BOTTOM of the page = Slide "Out"
-------------------------------------------------------------------------------

我无法弄清楚页面滚动定位(或第三步):

http://jsfiddle.net/B7pJL/1/

var slide = $("div[data-slide='true']");
var opening = false;
var closing = false;

$(window).scroll(function() {
var pos = $(window).scrollTop();
console.log(pos);
if (pos > 100) {
    if (!opening) {
        opening = true; closing = false;
        slide.stop().animate({
            opacity: 1,
            'margin-left': -350
        }, 1350, function() {
            opening = false;
        });
    }

} else {
    if (!closing) {
        closing = true; opening = false;
        slide.stop().animate({
            opacity: 0,
            'margin-left': 0
        }, 500, function() {
            closing = false;
        });
    }
}
});

0 个答案:

没有答案