$(function () { // $('.nav li a').each(function () { // var url = window.location.pathname; // var href=$(this).attr('href'); // var hrefSuffix = href.substr(2,href.length-1) // if(url.includes(hrefSuffix)){ // $(this).parent().addClass('on').siblings().removeClass('on') // } // }) // $('.nav li a').each(function () { // var url = window.location.pathname; // var href = $(this).attr('href'); // if (url == href) { // $(this).addClass('on').siblings().removeClass('on') // } // }) // $('.nav li a').each(function () { // var url = window.location.pathname; // var href = $(this).attr('href'); // if(url.includes('yingchao')){ // if (href.includes('yingchao')) { // $(this).parent().addClass('on').siblings().removeClass('on') // } // }else{ // if (href != '/' && url.includes(href)) { // $(this).parent().addClass('on').siblings().removeClass('on') // } // } // }) var currentPath = window.location.pathname; // 定义映射规则(支持正则) var pathMapping = [ { pattern: /^\/zuqiuzhibo\//, target: '/zq/' }, { pattern: /^\/lanqiuzhibo\//, target: '/lq/' }, { pattern: /^\/zqluxiang\//, target: '/luxiang/' }, { pattern: /^\/lqluxiang\//, target: '/luxiang/' }, { pattern: /^\/zqjijin\//, target: '/jijin/' }, { pattern: /^\/lqjijin\//, target: '/jijin/' }, { pattern: /^\/zqnews\//, target: '/news/' }, { pattern: /^\/lqnews\//, target: '/news/' } ]; // 匹配映射规则 var mappedPath = currentPath; for (var i = 0; i < pathMapping.length; i++) { if (pathMapping[i].pattern.test(currentPath)) { mappedPath = pathMapping[i].target; break; } } // 后续代码同上... $(".nav li").each(function() { var $li = $(this); var $link = $li.find("a"); var href = $link.attr("href"); var isMatch = false; if (href === "/") { isMatch = (mappedPath === "/" || mappedPath === "/index.php"); } else { isMatch = (mappedPath.indexOf(href) !== -1); } if (isMatch) { $li.addClass("on").siblings().removeClass("on"); return false; } }); }) //top function gotoTop(min_height){ //预定义返回顶部的html代码,它的css样式默认为不显示 var gotoTop_html = '
'; //将返回顶部的html代码插入页面上id为page的元素的末尾 $("body").append(gotoTop_html); $("#gotoTop").click(//定义返回顶部点击向上滚动的动画 function(){$('html,body').animate({scrollTop:0},200); }).hover(//为返回顶部增加鼠标进入的反馈效果,用添加删除css类实现 function(){$(this).addClass("hover");}, function(){$(this).removeClass("hover"); }); //获取页面的最小高度,无传入值则默认为600像素 min_height ? min_height = min_height : min_height = 600; //为窗口的scroll事件绑定处理函数 $(window).scroll(function(){ //获取窗口的滚动条的垂直位置 var s = $(window).scrollTop(); //当窗口的滚动条的垂直位置大于页面的最小高度时,让返回顶部元素渐现,否则渐隐 if( s > min_height){ $("#gotoTop").fadeIn(100); }else{ $("#gotoTop").fadeOut(200); }; }); }; gotoTop(); len = $(".bt-link1 a").length - 1; $(".bt-link1 a1").each(function(i) { var let = new Array( '27ea80','3366FF','ff5473','df27ea', '31ac76', 'ea4563', '31a6a0', '8e7daa', '4fad7b', 'f99f13', 'f85200', '666666'); var random1 = Math.floor(Math.random() * 12) + 0; var num = Math.floor(Math.random() * 5 + 12); $(this).attr('style', 'color:#' + let[random1] + '; opacity: ;'+''); if ($(this).next().length > 0) { last = $(this).next().position().left } });