スムーススクロール PC/SP高さそれぞれ調整
// スムーススクロール
if ((navigator.userAgent.indexOf('iPhone') > 0) || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0)
{
jQuery(document).ready(function(){
var adjust = -25;
var time = 500;
var urlHash = location.hash;
if(urlHash) {
jQuery('body,html').stop().scrollTop(0);
setTimeout(function () {
scrollToAnker(urlHash) ;
}, 100);
}
jQuery('a[href^="#"]').on('click', function(event) {
event.preventDefault();
var decodedHash = decodeURI(this.hash);
console.log(decodedHash);
var hash = decodedHash == "#" || decodedHash == "" ? 'html' : decodedHash;
scrollToAnker(hash);
return false;
});
function scrollToAnker(hash) {
var target = jQuery(hash);
var position = target.offset().top + adjust;
jQuery('body,html').stop().animate({scrollTop:position}, time, 'swing');
}
})
}
else {
jQuery(document).ready(function(){
var adjust = 0;
var time = 500;
var urlHash = location.hash;
if(urlHash) {
jQuery('body,html').stop().scrollTop(0);
setTimeout(function () {
scrollToAnker(urlHash) ;
}, 100);
}
jQuery('a[href^="#"]').on('click', function(event) {
event.preventDefault();
var decodedHash = decodeURI(this.hash);
console.log(decodedHash);
var hash = decodedHash == "#" || decodedHash == "" ? 'html' : decodedHash;
scrollToAnker(hash);
return false;
});
function scrollToAnker(hash) {
var target = jQuery(hash);
var position = target.offset().top + adjust;
jQuery('body,html').stop().animate({scrollTop:position}, time, 'swing');
}
})
}