keitahirai
3/22/2014 - 10:59 AM

ナビゲーションの自動ハイライト

ナビゲーションの自動ハイライト

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="css-js/active.js"></script>
$(function() {
    if(location.pathname != "/") {
        var $path = location.href.split('/');
        var $endPath = $path.slice($path.length-2,$path.length-1);
        $('nav li a[href$="'+$endPath+'/"]').addClass('active');
        var ovName = "_o";
        $("nav li a.active img").each(function(){
 
            var self = $(this);
            //画像置換
            var imgChange = function (elm,str1,str2){
                elm.attr("src",self.attr("src").replace(new RegExp("^(\.+)"+str1+"(\\.[a-z]+)$"),"$1"+str2+"$2"));
            }
            $(function() {
                imgChange(self,"",ovName);
            });
        });
    };
});
$(function() {
	if(location.pathname != "/") {
		var $path = location.href.split('/');
		var $endPath = $path.slice($path.length-2,$path.length-1);
		$('nav li a[href$="'+$endPath+'/"]').addClass('active');
	}
});