jQuery - Image starts off invisible then fades in when user scrolls -


i'm close achieving effect want, have 1 obstacle left don't know how solve.

basically, want start off image (that says "a new era of hosting), then, user scrolls, image fades out, , new 1 fades in, saying "tired of hosting kids?"

i'm close achieving effect. problem is, page loads, both of images visible, , second 1 disappears begin scrolling. how make second image isn't visible when page loads?

here jquery code, given question. please note haven't learnt jquery yet, , way have edited may amateurish or flat out wrong.

$(document).ready(function () {     var subsection2top = $('.sub-section2').offset().top;      $(window).scroll(function () {         var y = $(window).scrolltop();         if (subsection2top + 500 < y) {             $('.sub-section2').fadeto(100, 1);         } else {             $('.sub-section2').fadeto(100, 0);         }     }); });  $(document).ready(function () {     var subsectiontop = $('.sub-section').offset().top;      $(window).scroll(function () {         var y = $(window).scrolltop();         if (subsectiontop + 300 < y) {             $('.sub-section').fadeto(100, 0);         } else {             $('.sub-section').fadeto(100, 1);         }     }); }); 

also, here jsfiddle of of code.

thank in advance!

add ready function.

$('.sub-section2').hide(); 

also didn't why have ready functions write once this.

$(document).ready(function () { var subsection2top = $('.sub-section2').offset().top; var subsectiontop = $('.sub-section').offset().top; $('.sub-section2').hide(); $(window).scroll(function () {     var y = $(window).scrolltop();     if (subsection2top + 500 < y) {         $('.sub-section2').fadeto(100, 1);     } else {         $('.sub-section2').fadeto(100, 0);     }     if (subsectiontop + 300 < y) {         $('.sub-section').fadeto(100, 0);     } else {         $('.sub-section').fadeto(100, 1);     } }); }); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -