Javascript Jquery滚动到div并显示特定时间并隐藏
我正在寻找执行如下查询- 关于文档就绪事件。如果cookie值为1,则滚动至特定div并显示3秒,然后隐藏并删除cookie 这是我的juery代码: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
$(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);
}
});
}
});