How to Scroll page from top to an element on page
<script>
var onm = jQuery.noConflict(); // we use it to resolve conflict problem
onm(document).ready(function(){
scrollToElement(onm('.content_wrapper_arrow')); // you can also use id ex- onm("#idname");
});
function scrollToElement(ele) {
onm(window).scrollTop(ele.offset().top).scrollLeft(ele.offset().left);
}
</script>
you can also create a jquery function for smooth scrolling to a div -
<a href="#element-id" class="classname">Jump</a>
<!-- The scripts on bottom -->
<script type="text/javascript">
$(document).ready(function(){
function myscrollpage( _selector, _speed ){
_speed = parseInt(_speed, 10) === _speed ? _speed : 300;
$( _selector ).on('click', function(event){
event.preventDefault();
var url = $(this).attr('href'); //cache the url.
// Animate the jump
$("html, body").animate({
scrollTop: parseInt( $(url).offset().top ) - 50
}, _speed);
});
}
});
// Function call
myscrollpage( '.classname', 500);
</script>
And if you want scrolling to internal links you can do it in two ways:-
1) [via Javascript (+jQuery)]
<a href="#" id="home">home</a>
$('#home').click(function(){
$(document).scrollTop(100); // any value you need
});
2) [via pure HTML]
<a href="#home_section">home</a>
<section id="home_section"></section>
other examples for smooth scrolling to top----
scrollTop: $(window).scrollTop() + 100
var $container = $("html,body");
var $scrollTo = $('.saveIcon');
$container.animate({scrollTop: $scrollTo.offset().top - $container.offset().top, scrollLeft: 0},300);
Comments
Post a Comment