| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- $(function () {
- try {
- initTableStyle();
- } catch (error) {
- console.error(error);
- }
- // 移动端导航显示、隐藏
- try {
- $(".mobile-nav-icon").click(function () {
- if ($(".mobile-header-nav").css("opacity") == "0") {
- var headerHeight = $(".header-img").height();
- var windowHeight = $(window).height();
- $(".mobile-header-nav").height(windowHeight - headerHeight);
- $(".mobile-header-nav").css({
- "top": headerHeight + "px",
- "opacity": "1"
- })
- $(".mobile-header-nav").animate({
- "right": "0",
- }, 100)
- $(this).addClass("nav-icon-active");
- $("body").addClass("not-roll");
- } else {
- $(".mobile-header-nav").animate({
- "right": "-100%",
- "opacity": "0"
- }, 100);
- $(this).removeClass("nav-icon-active");
- $("body").removeClass("not-roll");
- }
- })
- } catch (error) {
- console.error(error)
- }
- try {
- // 移动端导航子栏目显示与隐藏
- $(".mobile-header-nav li").on("click", "a", function (e) {
- var len = $(this).next("ul").length;
- if (len > 0) {
- window.event ? window.event.cancelBubble = true : e.stopPropagation();
- $(this).parent("li").siblings().find("ul").hide();
- $(this).next("ul").slideToggle(200);
- }
- })
- } catch (error) {
- console.error(error)
- }
- try {
- //返回顶部
- $('.top').hide();
- $(window).scroll(function () {
- if ($(window).scrollTop() >= 200) {
- $('.top').fadeIn(300);
- } else { $('.top').fadeOut(300); }
- });
- $('.top').click(function () { $('html,body').animate({ scrollTop: '0px' }, 200); });
- } catch (error) {
- console.error(error)
- }
- try {
- $('#search').bind('keypress', function (event) {
- if (event.keyCode == 13) {
- if ($("#search").val().trim().length == 0) {
- return;
- }
- location.href = "/search?str=" + $("#search").val();
- }
- });
- $('#search-btn').bind('click', function (event) {
- if ($("#search").val().trim().length == 0) {
- $('#search').focus();
- return;
- }
- location.href = "/search?str=" + $("#search").val();
- });
- } catch (error) {
- console.error(error)
- }
- try {
- clearImgTextIndent();
- } catch (error) {
- console.error(error);
- }
- try {
- replaceMobileATarget();
- } catch (error) {
- console.error(error);
- }
- })
- function initTableStyle() {
- var articleMain = $("div.article-main");
- if (articleMain.length == 0) {
- return;
- }
- $("head").append('<link rel="stylesheet" type="text/css" href="/main/dist/websites/css/table.css"> ')
- $(articleMain).find("tr").attr("style", "");
- $(articleMain).find("td").attr("style", "");
- $(articleMain).find("table").attr("style", "");
- $(articleMain).find("table").addClass("layui-table");
- }
- // 解决旧网站抓取的图片不居中的问题
- function clearImgTextIndent() {
- var pAry = $("div.article-main").find("p");
- for (var i = 0; i < pAry.length; i++) {
- if ($(pAry[i]).find("img").length > 0) {
- $(pAry[i]).css("textIndent", "inherit")
- }
- }
- }
- // 如果是移动端,就把所有的新窗口改为当前页面打开
- function replaceMobileATarget() {
- if(isMobile()) {
- $("a").attr("target", "_self");
- }
- }
- function isMobile() {
- let userAgentInfo = navigator.userAgent;
- let mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
- let mobile_flag = false;
- //根据userAgent判断是否是手机
- for (let v = 0; v < mobileAgents.length; v++) {
- if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
- mobile_flag = true;
- break;
- }
- }
- return mobile_flag;
- }
|