/* jquery.util.js Update 2017.10.03 Version 1.1 */ jQuery(function($) { $('a[href^=#]').click(function(){ var speed = 500; var href= $(this).attr("href"); var target = $(href == "#" || href == "" ? 'html' : href); var position = target.offset().top - 50; $("html, body").animate({scrollTop:position}, speed, "swing"); return false; }); //---- ルートURL取得 var root; var js_path = 'js/'; var scripts = document.getElementsByTagName("script"); var i = scripts.length; while (i--) { var match = scripts[i].src.match(/(^|.*\/)\/?jquery\.util\.js$/); if (match) { root = match[1].replace(js_path,''); break; } } //---- URLのパターン解析 var url = document.URL; url = url.replace(root,''); //---- ロールオーバー var btnOver = function(){ $('body .over').each(function(i){ var target = $(this); var img = $(this).find('img'); var src = img.attr('src'); var tmp = new Image(); var hover_tmp = new Image(); var link = $(this).attr('href'); link = link.replace(root,''); var tmp_url = src.replace(/\.(jpe*g|gif|png)(.*)?$/,'_cr.$1$2'); var hover_url = src.replace(/\.(jpe*g|gif|png)(.*)?$/,'_on.$1$2'); var hover_action = function(){ //onの画像チェック hover_tmp.src = hover_url; hover_tmp.onload = function(){ target.hover( function(){ img.attr('src',hover_url); }, function(){ img.attr('src',src); } ); } } if(url == link){ tmp.onload = function(){ img.attr('src',src.replace(/.(jpe*g|gif|png)(.*)?$/,'_cr.$1$2')); } tmp.onerror = function(){ hover_action(); } tmp.src = tmp_url; } else { hover_action(); } }); } /* ------ 実行部 -------- */ $(function(){ btnOver(); }); });