建立自定义面板


// 建立自定义的面板
export default class viewerPanel {
    constructor() {
        this.setVisibleFunction()
        this.visibilityCallbacks = {};
        this.addVisibilityListenerFunction();
    }
    // 建立viewer面板
    creatViewerPanel(container,id,title){
        container.append(`<div class="panel-black viewer-panel" id="${id}" count="${this.count}">
            <div class="title panel-title">
                ${title}
                <span class="panel-close iconfont icon-close"></span>
            </div>
            <div class="panel-container">
                
                <div id="${id}-scroll-container" class="panel-container-scroll">
                   
                </div>
            </div>
        
        </div>`)
        $(".panel-close").on("click",function () {
            $(this).parent().parent().setVisible(false)

        })
        // 缩放
        $("#"+id).resizable();
        //  拖拽
        $("#"+id).draggable({ containment: "body", scroll: false , handle: ".panel-title"});
        return $("#"+id);
    }
    // 设置visible函数
    setVisibleFunction(){
        var _this = this;
        $.fn.setVisible = function(flag){
            var count = $(this).attr("id")
            if(flag){
                $(this).show()
            }else{
                $(this).hide()
            }
            _this.visibilityCallbacks[count](flag);

        }
    }
    // 增加监听函数
    addVisibilityListenerFunction(){
        var _this = this
        $.fn.addVisibilityListener = function(callBack){
            var count = $(this).attr("id")
            _this.visibilityCallbacks[count] = callBack
        }

    }
}
    原文作者:weijie
    原文地址: https://segmentfault.com/a/1190000019026799
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞