$(function () { $('.cate1').on('click', function () { $('.sub-menu').hide(300); $('.cate1').removeClass('hover'); $(this).addClass('hover'); $(this).find($('.sub-menu')).slideToggle(300); }); $('.open_menu').on('click', function () { $('.sub-menu').hide(300); $('.cate1').removeClass('hover'); $('.header-mid').slideToggle(300); if ($('.open_menu .iconfont').hasClass('icon-menu')) { $('.open_menu .iconfont').removeClass('icon-menu'); $('.open_menu .iconfont').addClass('icon-close'); } else { $('.open_menu .iconfont').removeClass('icon-close'); $('.open_menu .iconfont').addClass('icon-menu'); } if (!$('.header-mid').hasClass('nav-mini')) { $('.header-mid').addClass('nav-mini'); } else { $('.header-mid').removeClass('nav-mini'); } }) $(window).on('resize', function () { $('.sub-menu').removeAttr("style"); $('.header-mid').removeAttr("style"); }) $(window).scroll(function () { let scrollTop = $(window).scrollTop(); let aa = $('header').height(); if (scrollTop > aa*2) { $('body').addClass('_mini'); } else { $('body').removeClass('_mini'); } }); //取消未授权 var t = document.title; t = t.replace(" - 域名未授权", ""); $(document).attr("title", t); //打开搜索 $(".search_close").on('click', function () { if ($('.search_bar').hasClass('open')) { $('.search_bar').removeClass('open'); } else { $('.search_bar').addClass('open'); } }); $(".top-search").on('click', function () { if ($('.search_bar').hasClass('open')) { $('.search_bar').removeClass('open'); } else { $('.search_bar').addClass('open'); } }); //内页菜单 var sname = ""; $("#subnav li").hover(function () { sname = $(this).attr("class"); if (!sname) { $(this).addClass("hover"); } $("dl", this).show(); }, function () { $("dl", this).hide(); if (!sname) { $(this).removeClass("hover"); } }); //赞一下、踩一下 if ($(".digs").length > 0) { $(".digs").click(function () { var url = $(this).attr("data-url"); var that = this; $.ajax({ type: "post", url: url, dataType: "json", error: function () { alert("服务器错误") }, success: function (d) { if (d.state == 'success') { $(that).find("em").html(d.msg); } else { alert(d.msg) } } }) }); } //返回顶部 var top = $("#backtop"); $(window).scroll(function () { if ($(window).scrollTop() > 150) { top.slideDown(); } else { top.slideUp(); } }); }); //限制字数 $.fn.moreText = function (options) { var defaults = { maxLength: 50, mainCell: ".limit-text", openBtn: '显示全部', closeBtn: '收起' }; return this.each(function () { var _this = $(this); var opts = $.extend({}, defaults, options); var maxLength = opts.maxLength; var TextBox = $(opts.mainCell, _this); var openBtn = opts.openBtn; var closeBtn = opts.closeBtn; var countText = TextBox.html(); var newHtml = ''; if (countText.length > maxLength) { newHtml = countText.substring(0, maxLength) + '...' + openBtn + ''; } else { newHtml = countText; } TextBox.html(newHtml); TextBox.on("click", ".more", function () { if ($(this).text() == openBtn) { TextBox.html(countText + ' ' + closeBtn + ''); } else { TextBox.html(newHtml); } }) }) };