javascript - JS - how to remove setTimeOut for my code -


i trying use vertical scroll display object a. idea if scroll height greater scrollheight (15), after 1.2 second, a show up. when scroll top, hide.

the problem right if dont use cleartimeout, settimeout ignore condition: if ( scroll >= scrollheight )

when use cleartimeout, seems works when scroll or doesnt work.

here code.

var scrollheight = 15;  $(window).scroll(function() {     var scroll = getcurrentscroll();     var delaythis;      if ( scroll >= scrollheight ) {         delaythis = settimeout(function(){          //display **a**...           }, 1200);         }        else{         // hide **a** ...         cleartimeout(delaythis);         }   } 

thank helping!!

you have tell script if message showing or not, way avoid multiple delays. below working version of i'm talking about. hope helps.

var scrollheight = 15;  var message = $( ".message" );   var messagestatus = false;  var scrollposition;    $(window).scroll(function() {       scrollposition = $(document).scrolltop();            if ( scrollposition >= scrollheight ) {          if ( messagestatus == false ) {              settimeout(function(){                    message.show();                  messagestatus = true;                                }, 1200);          }        } else{          message.hide();          messagestatus = false;      }   });
.message {      display: none;      position: fixed;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <p>top</p>  <div class="message">      show!  </div>  <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <br /><br /><br /><br /><br />  <p>bottom</p>


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -