$(document).on('click', 'a', function(e) {
e.preventDefault();
const blank = $(this).attr('target');
const fromDomain = location.origin;
const from = fromDomain + location.pathname + location.search;
const to = $(this).prop('href');
const check = to.replace(from,'');
if(blank == '_blank' || to.indexOf(fromDomain) == -1) {
hrefBlank(to);
} else if( check.indexOf('#') == 0 || check == '') {
var target = 0;
if (check != '') {
target = $(check).offset().top;
}
hrefInPage(target);
} else {
hrefPageToPage(to);
}
});
function hrefBlank(target) {
window.open(target, '_blank');
}
function hrefPageToPage(target) {
// ローディング演出
$("演出に使ったDOM要素").on('animationend webkitAnimationEnd',function(){
window.location = target;
});
}
function hrefInPage(target) {
$('body,html').stop().animate({scrollTop:target}, 800);
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter