滚动到页面底部时更改背景位置
Change background position when scrolled to bottom of page
嗨,当页面一直滚动到底部时,我需要我的背景位置上升 50px。有什么办法可以做到这一点吗?
$(window).scroll(function() {
//Checking if scrolled to the bottom
if($(window).scrollTop() + $(window).height() == $(document).height()) {
//Adding background position CSS property to the desired element
$('.YOUR-ELEMENT-CLASS').css('background-position', '0 50px');
}
else {
$('.YOUR-ELEMENT-CLASS').css('background-position', 'default_values');
}
});
我不知道
你想要你的背景位置是什么,但说它是 0 100px,你希望它上升到 50px,假设你的元素的 id 为 #wrapper 你会做这样的事情:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
$('#wrapper').css('background-position', "0 50px");
}
});
这也是另一种方法...
$(window).scroll(function() {
if ( document.documentElement.clientHeight +
$(document).scrollTop() >= document.body.offsetHeight )
{
//add here your CSS code for changing color and do whatever you want
}
});
我知道这与以前的代码相同,但我也想为 Stack Overflow 贡献一个答案!
相关文章:
- jQuery-仅更改Y轴的CSS背景位置
- 仅为背景位置X轴制作动画
- 如何将CSS背景位置属性从百分比转换为像素
- 使用 jQuery 限制滚动时的垂直背景位置
- 视差/背景位置的特征检测
- 根据背景位置更改光标 URL
- 精灵图像的背景位置在 IE 中不起作用,用于倒计时时钟
- 如何在背景图像到达底部时停止背景位置更改
- IE10 背景位置 x 的解决方法
- 根据当前背景位置更改背景位置
- 在 Javascript 中获取 posX 和 posY 的背景位置
- 通过 javascript 通过增量修改 CSS 背景位置
- 用于更改背景位置的动态变量
- 背景位置:固定
- 滚动到页面底部时更改背景位置
- 更改其背景位置时,背景图像消失
- 使用 jquery 或 javaScript 更改背景位置的值
- 使用 jQuery 设置背景位置
- 根据鼠标移动将背景位置 x px 向左/向右移动(从背景位置:中心开始)
- 使用Javascript设置图像的背景位置