Auto Scroll with next page Section
jQuery :
function scrollToID(id, speed) {
try {
var offSet = 104;
var obj = $(id).offset();
var targetOffset = ($(id).offset().top - offSet);
$('html,body').animate({ scrollTop: targetOffset }, speed);
sessionStorage.removeItem('pg_id')
} catch (err) {
}
}
$(document).ready(function () {
if (sessionStorage.getItem('pg_id') !== '#undefined' && sessionStorage.getItem('pg_id') != null) {
// get sessionStorage for page id
var get_id = sessionStorage.getItem('pg_id');
scrollToID(get_id, 300);
}
// click event to scroll to div
$('.sub-navigation li a').on('click', function () {
sessionStorage.removeItem('pg_id')
var id = $(this).data('id');
if (id !== undefined) {
sessionStorage.setItem('pg_id', '#' + id);
scrollToID(id, 300);
}
});
});
HTML
Navigation link
<li><a href="test.html" data-id="philosophy"> Philosophy</a></li>
Next Page HTML
<section id="philosophy">
</section>
function scrollToID(id, speed) {
try {
var offSet = 104;
var obj = $(id).offset();
var targetOffset = ($(id).offset().top - offSet);
$('html,body').animate({ scrollTop: targetOffset }, speed);
sessionStorage.removeItem('pg_id')
} catch (err) {
}
}
$(document).ready(function () {
if (sessionStorage.getItem('pg_id') !== '#undefined' && sessionStorage.getItem('pg_id') != null) {
// get sessionStorage for page id
var get_id = sessionStorage.getItem('pg_id');
scrollToID(get_id, 300);
}
// click event to scroll to div
$('.sub-navigation li a').on('click', function () {
sessionStorage.removeItem('pg_id')
var id = $(this).data('id');
if (id !== undefined) {
sessionStorage.setItem('pg_id', '#' + id);
scrollToID(id, 300);
}
});
});
HTML
Navigation link
<li><a href="test.html" data-id="philosophy"> Philosophy</a></li>
Next Page HTML
<section id="philosophy">
</section>
Comments
Post a Comment