Javascript 更改背景图像,滚动显示(每个部分的图像不同)
有没有办法在特定区域滚动时更改背景img。 正如您在小提琴(jsfiddle.net/vwxxjhg1/)中看到的,我在左边有一个小图标。因此,当图标移动(或页面移动时,图标作为固定位置,如我所做的)并到达灰色区域时,是否应更改图标的背景img。下一个白色部分是3。背景图像。。。等等 谢谢你的建议Javascript 更改背景图像,滚动显示(每个部分的图像不同),javascript,jquery,html,css,image,Javascript,Jquery,Html,Css,Image,有没有办法在特定区域滚动时更改背景img。 正如您在小提琴(jsfiddle.net/vwxxjhg1/)中看到的,我在左边有一个小图标。因此,当图标移动(或页面移动时,图标作为固定位置,如我所做的)并到达灰色区域时,是否应更改图标的背景img。下一个白色部分是3。背景图像。。。等等 谢谢你的建议 I think its helps to you . jQuery(window).scroll(function(){ var fromTopPx = 200; // distance to tri
I think its helps to you .
jQuery(window).scroll(function(){
var fromTopPx = 200; // distance to trigger
var scrolledFromtop = jQuery(window).scrollTop();
if(scrolledFromtop > fromTopPx){
jQuery('html').addClass('scrolled');
}else{
jQuery('html').removeClass('scrolled');
}
});
And in your CSS file:
html {
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
html {
background-image:url(http://robt.info/wp-content/uploads/2013/06/funny-kids-comic-animals.jpg);
}
html.scrolled {
background-image:url(http://robt.info/wp-content/uploads/2013/06/funny-kids-comic-animals_2.jpg);
}