-2

Hi I am currently have a function to reveal images on this site, if you scroll down on homepage you will see the image being reveals as well as on this page.

Here's the JS, however the scrollTop part doesn't seem to be working on IE and Firefox, my developer wrote this and I am trying to fix it myself without his help..

revealImages: function() {
  var currentScroll = 0;
  var totalScroll = $(document).height() - $(window).height();
  var newScroll = $('body').scrollTop();

  $('.image-flip').each(function() {
    if(newScroll + $(window).height() >= $(this).offset().top + 200 && currentScroll < newScroll) $(this).addClass('flipped');
  });

  currentScroll = newScroll;
}
  • possible duplicate of [jQuery scrolltop firefox not working](http://stackoverflow.com/questions/17776544/jquery-scrolltop-firefox-not-working) – blex Mar 11 '15 at 20:52

1 Answers1

0

I found some bugs in your code.

var newScroll = $('body').scrollTop();

replace on

var newScroll = $('html, body').scrollTop();

FF return always 0 in your case.

Another bug is in your if statement. You forgot {}

This is a fix code

revealImages: function() {
  var currentScroll = 0;
  var totalScroll = $(document).height() - $(window).height();
  var newScroll = $('html, body').scrollTop();

  $('.image-flip').each(function() {
    if( ( newScroll + $(window).height() ) >= ( $(this).offset().top + 200 ) && ( currentScroll < newScroll ) ){
     $(this).addClass('flipped'); 
    }
  });

  currentScroll = newScroll;
}
FeDev
  • 27
  • 3
  • Re if statement: braces not required in this instance - http://stackoverflow.com/questions/7117873/do-if-statements-in-javascript-require-curly-braces – cssyphus Mar 11 '15 at 22:00