Reputation: 13
I have found a smooth-scrolling Jquery file written by this guy Karl Swedberg. The link is here: https://github.com/kswedberg/jquery-smooth-scroll. What i wanted is to make my navigation icon smooth-scroll to the anchor point once clicked. My Html code for navigation bar is here:
<div class="nav">
<ul>
<li class="icon"><a href="#info"><img src="./Img/info-64.png" alt="info-icon"></a></li>
<li class="icon"><a href="#education"><img src="./Img/Icon-edu.png" alt="info-icon"></a></li>
<li class="icon"><a href="#employment"><img src="./Img/Icon-employment.png" alt="info-icon"></a></li>
<li class="icon"><a href="#skill"><img src="./Img/Icon-skills.png" alt="info-icon"></a></li>
<li class="icon"><a href="#achievement"><img src="./Img/Icon-achiev.png" alt="info-icon"></a></li>
<li class="icon"><a href="#"><img src="./Img/photo-64.png" alt="info-icon"></a></li>
<li class="icon"><a href="#personality"><img src="./Img/Icon-personality.png" alt="info-icon"></a></li>
</ul>
</div>
It is a vertical navigation bar with many icons instead of text. The Jquery file is quite complicated for my current understanding, and i wouldn't be able to produce something more specific at this point yet. So your help is highly appreciated!
Upvotes: 0
Views: 194
Reputation: 964
using built in jquery animation would probably be easier. This page outline how to do this quite easily;
http://css-tricks.com/snippets/jquery/smooth-scrolling/
the code from there is this;
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
to use it add an anchor with href the same as the element you want to scroll to. e.g.
<a href="#one">link to div 1</a>
<div id="one"></div>
Upvotes: 1