0

How Can I make value in "%". I want to get dive show before 200% of the site and hide after. Thanks for any advice!

$(window).scroll(function() {

    if ($(this).scrollTop() > {percent:200})
     {
        $('.box').fadeOut();
     }
    else
     {
      $('.box').fadeIn();
     }
 });
Andreas
  • 154,647
  • 11
  • 152
  • 247
ownidea
  • 63
  • 7
  • **Java != JavaScript**. It even says so right there in the tooltips!!!!!! – Andreas Mar 27 '18 at 22:37
  • 200% of what? You mean like where the top of the page is 0% and the bottom of the page is 100%? If so, how do people scroll past the end of the page? – David784 Mar 27 '18 at 22:43
  • 3
    Possible duplicate of [Cross-Browser Method to Determine Vertical Scroll Percentage in Javascript](https://stackoverflow.com/questions/2387136/cross-browser-method-to-determine-vertical-scroll-percentage-in-javascript) – Stanislas Mar 27 '18 at 22:44
  • Not quite a perfect dup, but looking at [the accepted answer](https://stackoverflow.com/a/8028584/1270789), probably `var over200percent = (h[st]||b[st] > h.clientHeight * 2);` is close to what the OP wants, detecting when the user scrolls two pages worth? – Ken Y-N Mar 27 '18 at 23:38
  • `if ($(this).scrollTop() > {percent:200})` - you compare the result of `scrollTop()` with the object literal, which is wrong. – Thevs Mar 28 '18 at 07:40
  • 200% mean that I have got many sections in page. Each of it got 100% height. It doesn't matter for me its visible from top but just hidden past section "2" – ownidea Mar 28 '18 at 11:50

1 Answers1

0

multiply height with 2 for 200%

$(window).scroll(function() {
  if ($(this).scrollTop() > $(this).height() * 2){
    $('.box').fadeOut();
  }
  else{
    $('.box').fadeIn();
  }
});
Mustafa Çetin
  • 311
  • 2
  • 10