Advertisement
ipsBruno

(Javascript) Mudar URL conforme scroll no elemento

Sep 5th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  2. <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  3.  
  4. <script>
  5.  
  6. window.onscroll = function (oEvent) {
  7.    
  8.     $( "div" ).each(function() {       
  9.         if( $(this).offset().top <= window.pageYOffset && window.pageYOffset < $(this).offset().top
  10.  
  11. +$(this).height()) {
  12.         document.location.href = "#" + ($(this).html());
  13.         }
  14.     });}
  15.  
  16. </script>
  17.  
  18.  
  19. <div id="section1"><font size=10>ESSA É <br/><br/><br/><br/><br/><br/>DIV 1</font></div>
  20.  
  21.  
  22. <div id="section2"><font size=10>ESSA É <br/><br/><br/><br/><br/><br/>DIV 2</font></font></div>
  23.  
  24.  
  25. <div id="section3"><font size=10>ESSA É <br/><br/><br/><br/><br/><br/>DIV 3</font></font></div>
  26.  
  27. <div id="section4"><font size=10>ESSA É <br/><br/><br/><br/><br/><br/>DIV 4</font></font></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement