layui.define(['table', 'jquery', 'element'], function (exports) { "use strict"; var MOD_NAME = 'pearSocial', $ = layui.jquery, element = layui.element; var pearSocial = function (opt) { this.option = opt; }; pearSocial.prototype.render = function (opt) { //默认配置值 var option = { elem:opt.elem } createSocial(option); windowMove(option); return new pearSocial(option); } function createSocial(option){ var social = '
'; var body = ''; $("#"+option.elem).html(social+body); controlEvent(option); } function controlEvent(option){ $("#"+option.elem+" .pear-social .pear-social-control").on("click", "div", function() { var tool = $(this).attr("pear-id"); $("#"+option.elem+" .body").css({ display: "none" }); $("#"+option.elem+" .body[pear-id='" + tool + "']").css({ display: "block" }); $("#"+option.elem+" .pear-social-control div").removeClass("layui-this"); $(this).addClass("layui-this"); }) } // 记 住 原 来 的 位 置 var top; var left; // 放 大 $("body").on("click", ".screen-full", function() { top = $(this).parents(".pear-social").offset().top; left = $(this).parents(".pear-social").offset().left; $(this).parents(".pear-social").css({ top: '0px' }); $(this).parents(".pear-social").css({ left: '0px' }); $(this).parents(".pear-social").width("100%"); $(this).parents(".pear-social").height("100%"); $(this).removeClass("screen-full"); $(this).removeClass("layui-icon-screen-full"); $(this).addClass("screen-restore"); $(this).addClass("layui-icon-screen-restore"); }) $("body").on("click", ".screen-restore", function() { $(this).parents(".pear-social").css({ top: top }); $(this).parents(".pear-social").css({ left: left }); $(this).parents(".pear-social").width("1000px"); $(this).parents(".pear-social").height("550px"); $(this).addClass("screen-full"); $(this).addClass("layui-icon-screen-full"); $(this).removeClass("screen-restore"); $(this).removeClass("layui-icon-screen-restore"); }) function windowMove(option){ var disX = 0; var disY = 0; $('.pear-social-body-header').mousedown(function(ev) { disX = ev.pageX - $(this).offset().left + 300; //获取鼠标到元素的left,top位置 disY = ev.pageY - $(this).offset().top; var _this = $(this); $("#"+option.elem).mousemove(function(ev) { _this.parents('.pear-social').css('left', ev.pageX - disX); //获取移动后鼠标的位置,并重新赋值给元素 _this.parents('.pear-social').css('top', ev.pageY - disY); }); $("#"+option.elem).mouseup(function() { $("#"+option.elem).off(); }); return false; }); } $("body").on("click", ".window-close", function() { $(this).parents(".pear-social").css({ display: "none" }); }) $("body").on("click", ".pear-social-entrance", function() { $(this).parent().find(".pear-social").css({ display: "block" }); }) exports(MOD_NAME,new pearSocial()); })