image - How do I change my background on scroll using CSS? -


my website has perfect full page background image. grabbed code css tricks.

if visit my site can see in action.

what i'd know is, there way can have image change different image once scroll length?

my aim have same image speech bubble coming out of dogs mouth , i'm guessing 2 images this.

is possible in css only??????

here code using.

html {  background: url(http://robt.info/wp-content/uploads/2013/06/funny-kids-comic-animals.jpg) no-repeat center center fixed;  -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } 

as others said, nop, can't css, little js code can you.

ex.

jquery(window).scroll(function(){     var fromtoppx = 200; // distance trigger     var scrolledfromtop = jquery(window).scrolltop();     if(scrolledfromtop > fromtoppx){         jquery('html').addclass('scrolled');     }else{         jquery('html').removeclass('scrolled');     } }); 

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

so adding or removing class html tag @ distance top javascript (jquery in case)... , css, changing image.

now on.. can apply transitions image, or play code made slidetoggle example instead changing class.... , many many other options.

good luck

edit: fiddle example: http://jsfiddle.net/pzrcm/


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -