Saturday, December 27, 2014

jQuery-Parallax Scroll using jQuery

Parallax Scroll  using jQuery


<div>
  <ul>
   <li><a  href="#scroll1">Scroll 1</a></li>
   <li><a  href="#scroll2">Scroll 2</a></li>
   <li><a  href="#scroll3">Scroll 3</a></li>
   <li><a  href="#scroll4">Scroll 5</a></li>
   <li><a  href="#scroll5">Scroll 5</a></li>
  </ul>
</div>

<section id="scroll1" >Scroll Content 1  </section>
<section id="scroll2" >Scroll Content 2   </section>
<section id="scroll3" > Scroll Content 3  </section>
<section id="scroll4" > Scroll Content 4  </section>
<section id="scroll5" >Scroll Content 5   </section>


<script>
jQuery(function() {
  jQuery('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {

      var target = jQuery(this.hash);
      target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        jQuery('html,body').animate({
          scrollTop: target.offset().top - 140
        }, 1000);
        return false;
      }
    }
  });
});
</script>

Note: 1.Please be sure, jQuery libary has included for the page.
          2.  Put sufficient content section part.

Njoy the day :) :)

No comments :

Post a Comment