Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.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 更改背景图像,滚动显示(每个部分的图像不同)_Javascript_Jquery_Html_Css_Image - Fatal编程技术网

Javascript 更改背景图像,滚动显示(每个部分的图像不同)

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

有没有办法在特定区域滚动时更改背景img。 正如您在小提琴(jsfiddle.net/vwxxjhg1/)中看到的,我在左边有一个小图标。因此,当图标移动(或页面移动时,图标作为固定位置,如我所做的)并到达灰色区域时,是否应更改图标的背景img。下一个白色部分是3。背景图像。。。等等

谢谢你的建议

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);
    }