$(function () { // 获取包裹js的父元素class类名 function haveId() { let list = $("[class^=jsBoxscp"); let ids = []; for (let i = 0; i < list.length; i++) { let $elem = $(list[i]); let className = $elem.attr("class"); if (/^jsBoxscp-/isg.test(className)) continue; var suijiMath = Math.ceil(Math.random() * 1000000000); $(list[i]).removeClass('jsBoxscp').addClass("jsBoxscp-" + suijiMath); ids.push($elem.attr("class")); } return ids; }; // 如果有两个相同的文件,只会执行第一个文件里面的JS var AIboxIdb = haveId(); if (AIboxIdb.length > 0) { AIboxIdb.forEach(item => { let parentIDBox = $("." + item).parent().attr("id"); let parentID = $("#" + parentIDBox); $(".Fl10 a").parent().addClass('p_hLink'); $(parentID).find('.cateGoryArr').click(function () { $(this).next(".cateGory").animate({ height: 'toggle' }); }); }); } }); $(function () { var urlName = window.location.pathname; $('.e_container-43 .s_list .p_loopitem .s_title a').each(function () { var urlHref = $(this).attr('href'); if (urlName.indexOf(urlHref) >= 0) { $(this).addClass('on'); $(this).parent().parent("div").addClass('active'); } }); if ($(window).width() < 769) { if ($('.e_container-43 .s_list .p_loopitem.active').length > 0) { var left = $('.e_container-43 .s_list .p_loopitem.active').offset().left; console.log(left) console.log($(window).width() / 2) if (left > ($(window).width() / 2)) { $(".e_container-43 .s_list").scrollLeft(left / 2); } } } });