$(function () { $(".dropBtn").each(function () { let h = $(this).parents('dl').find(".head_drop > ul > li").length * 26 + 27; $(this).attr("height", h) }) layui.use(['layer'], function (args) { let winH = $(window).height(); let winW = $(window).width(); $(".dropBtn").click(function () { // if($(this).hasClass("open")){ // layer.close($(this).parents('dl').index()) // $(this).removeClass("open"); // return false; // } let index = $(this).parents('dl').index(); let that = $(this); $(this).addClass("open"); let title = $(this).text(); let content = $(this).parents('dl').find("dd").eq(0); let h = $(this).attr("height") * 1; let top = parseInt(Math.random(90, winH) * 1000); let left = Math.max(20, parseInt(Math.random(20, winW) * 1000)); let t = winH - h - 100; let l = winW - 176 - 20; console.log(index); if(index==3){ left = Math.min(l - 176, left); top = top < 90 ? 90 : Math.min(t - 200, top); }else{ top = top < 90 ? 90 : Math.min(t, top); left = Math.min(l, left); } console.log(top,left); index = layer.open({ type: 1, title:false, content, skin: "layer-header", shade: false, anim: 1, offset: [top + 'px', left + 'px'], // offset: ['100px', '500px'], maxWidth: '176px', maxHeight: 500, move: '.mine-move', cancel: function(index) { that.removeClass("open") layer.close(index); }, success: function() { } }) }) // $(".dropBtn").eq(2).click() }); }) $(".head_drop li .dropItem .layui-icon").click(function () { let parent = $(this).parent().parent(); if (parent.hasClass("on")) { parent.removeClass("on") parent.find(".dropInfo").eq(0).stop().slideUp() }else{ parent.addClass("on").siblings().removeClass("on") parent.find(".dropInfo").eq(0).stop().slideDown() parent.addClass("on").siblings().find(".on").removeClass("on") parent.siblings().find(".dropInfo").stop().slideUp() } return false; })