$(function () { layui.use(['carousel','element'], function () { var carousel = layui.carousel; //建造实例 $("[name='carousel']").each(function(){ var _this=$(this); var ins= carousel.render({ elem: _this , width: '100%' //设置容器宽度 , height: '100%' , arrow: 'hover' , anim: "fade" , "interval": 8000 }); initslide(ins); }) fixscaleobjsize(); }) screen.onresize(function (resizedwinwidth, resizedwinheight, scale) { fixscaleobjsize(); }); settimeout(function () { fixscaleobjsize(); },100) sitemenuevent(); }); var sitemenuevent=function () { $("[name='sitemenuitem']").find('.menuitem').each(function () { if($(this).find('.sitemenucontent').length>0){ (function (self) { var overtime = 0,outtime=0; self.mouseenter(function () { overtime=new date().gettime(); if((overtime - outtime)>280){ self.find('.sitemenucontent').slidedown(); } }).mouseleave(function () { outtime=new date().gettime(); self.find('.sitemenucontent').hide(); }) })($(this)); } }); } var fixscaleobjsize = function () { $("[scale]").each(function () { var _scale=$(this).attr("scale"); var width=$(this).width(); var height = width / number(_scale) $(this).height(height); }) } /** * 屏幕尺寸改变事件 * @type {{onresize: onresize}} */ var screen=function(cb) { var winwidth = $(window).width(); var winheigh = $(window).height(); var onresize = function(cb) { var resizedwinwidth = $(window).width(); var resizedwinheight = $(window).height(); var scale_w = resizedwinwidth / winwidth; var scale_h = resizedwinheight / winheigh; var scale = scale_w >= scale_h ? scale_h : scale_w; if (cb) { cb(resizedwinwidth, resizedwinheight, scale); } $(document).trigger("onresize", resizedwinwidth, resizedwinheight, scale); window.onresize = function() { onresize(cb); } }; return { onresize: onresize } }(); /** * 移动端菜单 */ function opensidemenu(obj){ var winheigh = $(window).height()-60; var isshow=$("[name='side-menu']").attr('data-show') || "0"; if(isshow=="0"){ obj.removeclass('layui-icon-shrink-right').addclass('layui-icon-spread-left'); $("[name='side-menu']").css("height",winheigh); $("[name='side-menu']").show(); $("[name='side-menu']").attr('data-show',"1"); }else{ obj.addclass('layui-icon-shrink-right').removeclass('layui-icon-spread-left'); $("[name='side-menu']").hide(); $("[name='side-menu']").attr('data-show',"0"); } } function ismobile(){ } function initslide (ins){ $(".layui-carousel").on("touchstart", function (e) { var startx = e.originalevent.targettouches[0].pagex;//开始坐标x $(this).on('touchmove', function (e) { arguments[0].preventdefault();//阻止手机浏览器默认事件 }); $(this).on('touchend', function (e) { var endx = e.originalevent.changedtouches[0].pagex;//结束坐标x e.stoppropagation();//停止dom事件逐层往上传播 if (endx - startx > 30) { ins.slide("sub"); } else if (startx - endx > 30) { ins.slide("add"); } $(this).off('touchmove touchend'); }); }); }