(function () { var lpkWidth = calculateViewportWidth(); var lpkHeight = calculateViewportHeight(); function calculateViewportWidth() { if (window.innerWidth) { return window.innerWidth; } if (document.documentElement && document.documentElement.clientWidth) { return document.documentElement.clientWidth; } return document.body.clientWidth; } function calculateViewportHeight() { if (window.innerHeight) { return window.innerHeight; } if (document.documentElement && document.documentElement.clientHeight) { return document.documentElement.clientHeight; } return document.body.clientHeight; } window.lpkWidth = lpkWidth; window.lpkHeight = lpkHeight; })(); (function (window) { var ENC = function () { }; ENC.prototype = { /** * @description 快捷键 可视化编辑隐藏 */ F8: function () { if (document.querySelectorAll('.VisualEditing')) { let $but = document.querySelectorAll('.VisualEditing') let $btnlen = $but.length if (sessionStorage.getItem('VisualEditing')) { for (let i = 0; i < $btnlen; i++) { $but[i].style.display = "none" } } document.addEventListener("keydown", function (event) { if (event.keyCode === 119) { if (!sessionStorage.getItem("VisualEditing")) { for (let i = 0; i < $btnlen; i++) { $but[i].style.display = "none" } sessionStorage.setItem('VisualEditing', true) } else { for (let i = 0; i < $btnlen; i++) { $but[i].style.display = "block" } sessionStorage.removeItem('VisualEditing') } } }); } }, /** * @description 可视化编辑跳转 */ VisualEditing: function () { if (document.querySelectorAll('.VisualEditing')) { document.querySelectorAll('.VisualEditing').forEach(item => { item.addEventListener('click', function (e) { e.preventDefault() e.stopPropagation() let body = document.querySelector('body') let link = document.createElement('a') link.href = e.target.dataset.href link.style.display = 'none' link.target = '_blank' body.appendChild(link) link.click() }) }) } }, /** * @description 滚动 */ scroll: function () { gsap.registerPlugin(ScrollTrigger, lpkscroll); let isMobile = ScrollTrigger.isTouch === 1 if (!isMobile) { lpkscroll.create({ smooth: 1, effects: true, }); } }, /** * @description 视频插入 */ videoInsertion: function () { var layer_str = '
' $('body').append(layer_str); $('.layerVideo .box span').click(function () { $('.layerVideo').fadeOut(); // $(".layerVideo video").trigger('pause'); $(".layerVideo video").remove(); $(".layerVideo iframe").remove(); }); }, /** * @description 视频弹窗 */ layerVideo: function (video) { let _thisVideo = $(video).attr("data-video"); $(".layerVideo video").remove(); $(".layerVideo iframe").remove(); if (/iframe/.test(_thisVideo)) { $(".layerVideo .box").append(_thisVideo); } else { let video = document.createElement('video'); video.src = _thisVideo video.controls = true; $(".layerVideo .box").append(video); $(".layerVideo video").get(0).play(); } $(".layerVideo").fadeIn(500); }, /** * @description 图片插入 */ ImgsInsertion: function () { var layer_Img = `
` $('body').append(layer_Img); $('.layerImg .close').click(function () { $(".layerImg img").attr('src', ' '); $('.layerImg').fadeOut(); }); }, /** * @description 图片弹窗 */ layerImg: function (img) { let _thisImg = $(img).attr("data-img"); $(".layerImg img").attr('src', _thisImg); $(".layerImg").fadeIn(500); }, /** * @description 禁止F12 * @param {*} event * @returns */ prohibitF12: function () { document.onkeydown = function (e) { var currKey = 0, evt = e || window.event; currKey = evt.keyCode || evt.which || evt.charCode; if (currKey == 123) { window.event.cancelBubble = true; // window.event.returnValue=false; window.event.preventDefault(); } } }, /** * @description 禁止右键 * @param {*} event * @returns */ prohibitRightButton: function () { document.oncontextmenu = function (event) { if (window.event) { event = window.event; } try { var the = event.srcElement; if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) { return false; } return true; } catch (e) { return false; } } }, /** * @description 禁止复制 * @param {*} event * @returns */ prohibitCopy: function () { document.oncopy = function (event) { if (window.event) { event = window.event; } try { var the = event.srcElement; if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) { return false; } return true; } catch (e) { return false; } } }, /** * @description 禁止剪切 * @param {*} event * @returns */ prohibitShear: function () { document.oncut = function (event) { if (window.event) { event = window.event; } try { var the = event.srcElement; if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) { return false; } return true; } catch (e) { return false; } } }, /** * @description 禁止选中 * @param {*} event * @returns */ prohibitSelect: function () { document.onselectstart = function (event) { if (window.event) { event = window.event; } try { var the = event.srcElement; if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) { return false; } return true; } catch (e) { return false; } } }, /** * @description 图片禁止拖拽 */ imgDrag: function () { $('img').each(function () { $(this).attr('draggable', 'false'); $(this).attr('loading', 'lazy'); }) }, /** * 下载文件 * @param {String} selector 选择器 */ fileDownload: function (selector) { let _thisName = $(selector).attr("data-name"); let _thisHref = $(selector).attr("data-href"); var aElement = document.createElement('a'); aElement.download = _thisName; aElement.href = _thisHref; $('body').append(aElement); aElement.click(); $(aElement).remove(); }, /** * @description 复制 * @param {String} text 文本内容 */ copyText: function (text) { var textarea = document.createElement('textarea'); textarea.value = text; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); document.body.removeChild(textarea); }, /** * @description 备案号 公安号 */ RecordNumber: function () { $('.Icp').attr('href', 'https://beian.miit.gov.cn/#/Integrated/index'); let ga = $('.GongAn').attr('data-number'); $('.GongAn').attr('href', "http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=" + ga); $('.zhulu').attr('href', 'https://zhulu86.com'); $('.Icp,.GongAn,.zhulu').attr('target', '_blank'); }, // 判断是否是在微信浏览 isWeiXin: function () { var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } }, // 判断是否在pc端,ipad端和移动端 isPC: function () { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } if (userAgentInfo.indexOf("iPhone") > 0) { return true; } else if (userAgentInfo.indexOf("Android") > 0) { return true; } else { return false; } }, /** * @description 判断是否有圆角 * @returns {Boolean} true:有圆角 false:没有圆角 */ hasRoundedCorners: function () { const style = document.createElement('style'); style.textContent = '.radius { -webkit-transform: rotate(0deg); }'; document.head.appendChild(style); const elements = document.querySelectorAll('*'); for (const element of elements) { const style = getComputedStyle(element); if (style.borderRadius && style.borderRadius !== '0px') { element.classList.add('radius') } } return false; }, /** * 数据加载 * @param {String} selector 选择器 */ dataLoading: function (selector) { selector = selector || '.dataLoading'; $(selector).countUp({ delay: 10, time: 1000 }); }, /** * 返回顶部 */ goTop: function (duration) { duration = duration || 0 $('.goTop').click(function () { $("html,body").stop().animate({ scrollTop: 0, }, duration) }); }, /** * @description 加载动画 * @param {String} selector id * @param {String} url 路径 */ lottie: function (selector, url) { lottie.loadAnimation({ container: document.getElementById(selector), renderer: 'svg', loop: true, autoplay: true, path: url }); }, /** * @description 计算svg长度 * @param {String} url 路径 */ svgLength: function (path) { let obj = document.querySelector(path); let length = obj.getTotalLength(); console.log(length) }, /** * 滚动页面显示位置 * @param {String} selector 选择器 */ waypointScroll: function (selector) { new Waypoint({ element: $(selector), handler: function (direction) { if (direction == 'down') { console.log(123) } if (direction == 'up') { console.log(456) } // this.destroy(); // 只执行一次 }, offset: '99%' // offset: 'bottom-in-view' // right-in-view }) }, /** * @description 页面平滑滚动 */ smooth: function () { SmoothScroll({ animationTime: 900, stepSize: 75, accelerationDelta: 30, accelerationMax: 2, keyboardSupport: !0, arrowScroll: 50, pulseAlgorithm: !0, pulseScale: 4, pulseNormalize: 1, touchpadSupport: !0 }); }, /** * 数字滚动 * @param {String} selector 选择器 * @param {Boolean} addZero 是否补0 * @param {Number} speed 滚动速度(ms) */ numRoll: function (selector, addZero, speed) { var $ele = $(selector); var speed = speed || 1000; $ele.appear(function () { var realContent = $(this).text(); $(this).width($(this).width()); var content = $(this).data("to"); if (!content) { content = realContent; }; var to = parseFloat(content.toString().replace(/,/g, "")); var length = parseInt(to).toString().length; var hasDou = false; var contentArr = content.toString().split(","); if (contentArr[1]) { hasDou = true; }; if (addZero) { formatter = function (value, options) { var myValue = value.toFixed(options.decimals); var valLength = parseInt(myValue).toString().length; for (var i = 0; i < (length - valLength); i++) { myValue = "0" + myValue; } if (hasDou) { myValue = toThousands(myValue); } return myValue; } } else { formatter = function (value, options) { var myValue = value.toFixed(options.decimals); if (hasDou) { myValue = toThousands(myValue); } return myValue; } } function toThousands(num) { return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); } $(this).countTo({ speed: speed, refreshInterval: 60, formatter: formatter, onComplete: function () { $(this).removeAttr("style"); $(this).text(realContent); } }); }); }, /** * @description 获取网站语言 */ getLang: function () { const htmlElement = document.documentElement; const language = htmlElement.lang; console.log(language); if(language == 'zh'){ htmlElement.classList.add('lang_zh') }else{ htmlElement.classList.add('lang_en') } } } window.lpk = new ENC(); })(window); /** * @description .svg 转svg */ // onload=SVGInject(this) (function () { lpk.getLang(); })();