Skip to content Skip to sidebar Skip to footer

Center A Section When Using Smooth Scroll

I am using Chris Ferdinandi's Smooth Scroll script and I am trying to have it scroll to an element, but land with that element centred. Similarly to what is done at http://www.spot

Solution 1:

Try

(function() {

   functionsetStuff(elementhref) {

      var elementheight = $(elementhref).height();
      var windowheight = $(window).height();

      if (elementheight < windowheight) {
        topoffset = ((windowheight / 2) - (elementheight / 2) - 30);
      } else {
       topoffset = 0;
      }

   }

   $('.downarrow a').click(function() {
     setStuff( $(this).attr('href') );
   });

})();

Only targeting the one you have 'clicked' - this - and making a jquery object of out it so you can access the jquery methods $(this)


Edit/Update - added in the parts to connect the click handler with a function to dostuff

Post a Comment for "Center A Section When Using Smooth Scroll"