Automatic Scroll Up


/ Published in: jQuery
Save to your folder(s)

Used to automatically scroll up the page so that it is focused on user entry (mobile devices)


Copy this code and paste it in your HTML
  1. var clicked = false;
  2.  
  3. $(document).on('click', '#msisdn-input' , function(e){
  4. e.preventDefault();
  5. if(clicked===false){
  6. window.scrollTo(0,1);
  7. clicked = true;
  8. }
  9. setTimeout(function(){
  10. $('#scroll').css('float','left');
  11. scrollSize = $('.submit-button').offset().top + $('.submit-button').outerHeight()+5;
  12. console.log(scrollSize);
  13. screenSize = $(window).height();
  14. result = (scrollSize-screenSize);
  15. if(result>0){
  16. $('html, body').animate({scrollTop:result},'200');
  17. }
  18. },700);
  19. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.