[英]jQuery on scroll header effect
嗨,大家好
我想在滚动标题效果上做一个jQuery 。 我刚刚在代码中添加了一些更改,但是它们无法按我想要的方式工作。 我想产生效果-当我向下滚动标题的一点像素以将高度更改为较小时。 或以其他样式显示隐藏的标题
因此,当滚动普通标题以向上滑动然后将隐藏的标题像向下滑动一样显示时...我已经花了很多时间,但是只能与fadeIn和fadeOut一起使用
jQuery code
$(function() {
$('.header-small').hide();
var header = $(".header-small");
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 200) {
$('.header-small').show();
header.removeClass('header').addClass("header-small");
$('.header-small').addClass('animated fadeInUp'), {duration:500};
} else {
$('header').show();
$('.header-small').hide();
header.removeClass("header-small").addClass('header');
$('header').addClass('animated fadeInDown');
}
});
});
在这里 工作演示
请有人可以帮我吗?
谢谢
您可以尝试使用回调,
$(function() {
$('.header-small').hide();
var bar = $('header');
var top = bar.css('top');
$(window).scroll(function() {
if($(this).scrollTop() > 50) {
bar.stop().animate({'top' : '0px'}, 200);
$('.header-small').slideDown('slow',function(){
$('header').slideUp('slow');});
} else {
bar.stop().animate({'top' : '20px'}, 200);
$('header').slideDown('slow');
$('.header-small').slideUp('slow');
}
});
});
还有一些造型以获得更清洁的效果
header
{
position:absolute;
width:400px;
height:200px;
}
为什么不只是添加类,其余的都在CSS中呢?
$(window).scroll(function() {
if($(window).scrollTop() > 50) {
$('header').addClass('header-small');
}
else {
$('header').removeClass('header-small');
}
});
$(function () {
$('.header-small').hide();
var bar = $('header');
var top = bar.css('top');
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
bar.stop().animate({
'top': '0px'
}, 200);
$('header').slideUp('fast', function () {
$('.header-small').slideDown('slow');
});
} else {
bar.stop().animate({
'top': '20px'
}, 200);
$('.header-small').slideUp('fast', function () {
$('header').slideDown('fast');
});
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.