Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery滚动到div并显示特定时间并隐藏_Javascript_Jquery_Cookies - Fatal编程技术网

Javascript Jquery滚动到div并显示特定时间并隐藏

Javascript Jquery滚动到div并显示特定时间并隐藏,javascript,jquery,cookies,Javascript,Jquery,Cookies,我正在寻找执行如下查询- 关于文档就绪事件。如果cookie值为1,则滚动至特定div并显示3秒,然后隐藏并删除cookie 这是我的juery代码: $(document).ready(function () { if ($.cookie("messageshow") != null) { $('html, body').animate({ scrollTop: $('.offset-message').offset().top }, 1

我正在寻找执行如下查询- 关于文档就绪事件。如果cookie值为1,则滚动至特定div并显示3秒,然后隐藏并删除cookie

这是我的juery代码:

$(document).ready(function () {
if ($.cookie("messageshow") != null) {
        $('html, body').animate({
            scrollTop: $('.offset-message').offset().top
        }, 1500);

        $(window).scroll( function(){
            var bottom_of_object = $('.offset-message').offset().top + $('.offset-message').outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();
            if( bottom_of_window > bottom_of_object ){
                $('.offset-message').fadeIn('slow').animate({opacity: 1, display:'block'}, 3000).fadeOut('slow'); 
            }  
        });
    }
});
信息部门CSS:

.offset-message{
    display: none;
    padding: 40px 70px;
    margin-bottom: 30px;
    background-color: #f5f5f5;
    text-align: center;
    opacity: 0;
}

似乎它没有按预期工作。当前,消息div(偏移消息)闪烁多次,然后隐藏

我认为fadeIn和animate都会影响不透明度值。您还可以立即调用淡出方法,这意味着有3种方法同时更改您的不透明度值

这应该可以解决这个问题:

$(document).ready(function () {
    if ($.cookie("messageshow") != null) {
        $('html, body').animate({
            scrollTop: $('.offset-message').offset().top
        }, 1500);

        $(window).scroll( function(){
            var bottom_of_object = $('.offset-message').offset().top + $('.offset-message').outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();
            if( bottom_of_window > bottom_of_object ){
                var sel = $('.offset-message')
                sel.fadeIn('slow');
                setTimeout(function(){ 
                    sel.fadeOut('slow');
                    //delete the cookie; 
                }, 3000); 
            }  
        });
    }
});

我认为fadeIn和animate都会影响不透明度值。您还可以立即调用淡出方法,这意味着有3种方法同时更改您的不透明度值

这应该可以解决这个问题:

$(document).ready(function () {
    if ($.cookie("messageshow") != null) {
        $('html, body').animate({
            scrollTop: $('.offset-message').offset().top
        }, 1500);

        $(window).scroll( function(){
            var bottom_of_object = $('.offset-message').offset().top + $('.offset-message').outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();
            if( bottom_of_window > bottom_of_object ){
                var sel = $('.offset-message')
                sel.fadeIn('slow');
                setTimeout(function(){ 
                    sel.fadeOut('slow');
                    //delete the cookie; 
                }, 3000); 
            }  
        });
    }
});