From start to finish, this quick tip with Andrew Chalkley will take you through an example using jQuery’s Smooth Scrolling on a FAQ page.
Andrew Chalkley
May 30, 2013
-
1 min read
From start to finish, this quick tip with Andrew Chalkley will take you through an example using jQuery’s Smooth Scrolling on a FAQ page.
GET STARTED NOW
Learning with Treehouse for only 30 minutes a day can teach you the skills needed to land the job that you’ve been dreaming about.
Get StartedYou might also like other posts...
Front-End vs. Back-End: The Complete Guide
If you're new to coding, you may be wondering what the difference is between front-end vs. back-end. Find your answers in our latest Treehouse blog.
Should I Learn HTML Before Python?
Starting your coding journey and wondering if you should learn HTML before Python? We've got you covered. Keep reading to learn the key differences in our latest blog.
How to Use the Browser Developer Tools Console
The developer console can help you debug your front-end web applications. Learn more about the browser developer tools in this quick and simple guide.
Start your 7 day free trial today and get access to hundreds of video courses in web development, design and business!
Learn more
how abt scrolling it horizontally… ?i tried below code.. but dint wrk 🙁
$( ‘html, body’ ).animate({ scrollTop : $( faqId ).offset().right}, ‘slow’);
@Vipin jquery offset() returns an object with the properties of left and top.
In your example, you could try:
$('html, body').animate({scrollTop:$(faqId).offset().left}, 'slow');
Hope it helps!
For more on jquery offset: http://api.jquery.com/offset
Great video capture. Explains it well 🙂 flowers puzzles
Nice tip! This works in Google Chrome / Safari / Firefox, but fail in IE. So, to work crossbrowser, just do it:
$( ‘html, body’ ).animate({ $( faqId ).offset().top }, ‘slow’);
And for best practices, use “event.preventDefault()” instead of “return false”;
The complete code:
$( ‘#faq a’ ).click( function( e ) {
e.preventDefault();
var faqId = $( this ).attr( ‘href’ );
$( ‘html, body’ ).animate({ scrollTop : $( faqId ).offset().top }, ‘slow’);
});
Great screencast, thanks for the tip!
Wow, quick tip…Thanks for this 🙂 Europe puzzles
Nice Quicktip. Would be nice to add a scrolling “link to top” for those who have longer FAQs that would bring the user back to the top..