Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Christian Espinola
1,192 PointsJavascript question
Hello, I'm trying to make this script scroll to the block nicely and i can't seem to figure out how to, anyone have an idea on how to make this have some kind of animated scroll or smooth scroll instead of an abrupt jump to the block?
/* name your links like: http://mypage.com/jump-to-block-3 or http://mypage.com/jump-to-block-6 */
/* place this in footer scripts */
$( document ).ready( function() {
var $containers = $( ".row[opt-type='block']" );
for ( var i = 0, l = $containers.length, deepLink; i < l; ++i ) {
deepLink = ( "op-container--" + i );
$containers.eq( i ).attr( "id", deepLink ).attr( "name", deepLink );
}
var $linksToFix = $( "a[href*='biblicalbusiness.com/jump-to-block']" );
for ( i = 0, l = $linksToFix.length; i < l; ++i ) {
deepLink = $linksToFix.eq( i ).attr( "href" ).split( "jump-to-block-" )[ 1 ];
$linksToFix.eq( i ).attr( "href", "#op-container--" + deepLink );
}
} );
at least something like this http://jsfiddle.net/YtJcL/
thank you in advance
2 Answers
Steven Parker
243,656 PointsThere are some other ways to scroll that can be made smooth.
You could use the scrollIntoView function, or use jQuery's animate to smoothly change the CSS ScrollTop property.
There's examples of both of these at this CSS Tricks page on Smooth Scrolling.
Christian Espinola
1,192 Pointsis there a way to add code to what i currently have? I'm new to this and its intimidating the bananas out of me lol