zoukankan      html  css  js  c++  java
  • 【原创】Jquery.Greybox.js(Jquery框架下的Greybox源代码)

    function GB_show(title, url, width, height, scroll) {
        var GB_HEIGHT = height || 400;
        var GB_WIDTH = width || 400;
        var scroll = scroll == null ? 'no' : scroll;
        var html = "\
                <div id='GB_overlay'><iframe id='GB_bgframe' scrolling='no' frameborder='0'></iframe></div>\
                <div id='GB_window'>\
                <div id='GB_caption'>" + title + "</div>\
                <img id='GB_closeimg' src='/images/greybox/close.gif' alt='Close window'/>\
                <img id='GB_loading' src='/Images/greybox/indicator.gif' align='absmiddle'/>\
                <iframe id='GB_frame' src='" + url + "' scrolling='" + scroll + "'></iframe>\
                </div>\
                ";
        $(document.body).append(html);
        $("html").css("overflow", "hidden");

        //position
        var GB_de = document.documentElement;
        var GB_w = Math.max(GB_de.offsetWidth, document.body.scrollWidth, GB_de.scrollWidth);
        var GB_h = Math.max(GB_de.offsetHeight, document.body.scrollHeight, GB_de.scrollHeight);
        var scrollleft = Math.max(GB_de.scrollLeft, document.body.scrollLeft);
        var scrolltop = Math.max(GB_de.scrollTop, document.body.scrollTop);
        var GB_left = ((GB_de.clientWidth - GB_WIDTH) / 2) + scrollleft;
        var GB_top = ((GB_de.clientHeight - GB_HEIGHT) / 2) + scrolltop;

        $("#GB_overlay").css({ GB_w + "px", height: GB_h + "px" });
        $("#GB_window").css({ GB_WIDTH + "px", height: GB_HEIGHT + "px", top: GB_top + "px", left: GB_left + "px" });
        $("#GB_frame").css({ height: GB_HEIGHT - 22 + "px" });

        //bind event
        $("#GB_window img").click(GB_hide);
        $("#GB_frame").load(function() { $("#GB_loading").hide(); $("#GB_frame").show(); });
        $("#GB_caption").mousedown(function(event) {
            var oObj = document.getElementById("GB_window");
            var oEvent = window.event || event;
            var dragData = { x: oEvent.clientX, y: oEvent.clientY };
            var backData = { x: parseInt(oObj.style.top), y: parseInt(oObj.style.left) };
            if ($.browser.msie) oObj.setCapture();
            oObj.onmousemove = function(event) {
                oEvent = window.event || event;
                var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
                var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
                oObj.style.left = iLeft + "px";
                oObj.style.top = iTop + "px";
                dragData = { x: oEvent.clientX, y: oEvent.clientY };
            }
            oObj.onmouseup = function(event) {
                oEvent = window.event || event;
                oObj.onmousemove = null;
                oObj.onmouseup = null;
                if (oEvent.clientX < 1 || oEvent.clientY < 1 || oEvent.clientX > document.documentElement.clientWidth || oEvent.clientY > document.documentElement.clientHeight) {
                    oObj.style.left = backData.y + "px";
                    oObj.style.top = backData.x + "px";
                }
                if ($.browser.msie) oObj.releaseCapture();
            }
        });
    }

    function GB_hide() {
        $("#GB_window,#GB_overlay").remove();
        $("html").css("overflow", "auto");
    }

  • 相关阅读:
    字典的增删改查
    基础数据类型
    Linux程序优化实践
    Linuxt性能调优指南
    【MySQL】Percona Toolkits工具介绍及使用
    【MySQL】如何构建高性能MySQL系统?
    【MySQL】Event使用案例
    【MySQL】事件调度器 (Event Scheduler)
    【MySQL】mydumper工具介绍
    spu与sku的含义
  • 原文地址:https://www.cnblogs.com/cosiray/p/1587259.html
Copyright © 2011-2022 走看看