js 遮罩效果 - 编程思维

 -------------------------------tipswindown.js------------------------------

///-------------------------------------------------------------------------
//jQuery弹出窗口 By Await [2009-11-22]
//--------------------------------------------------------------------------
/*参数:[可选参数在调用时可写可不写,其他为必写]
----------------------------------------------------------------------------
    title:    窗口标题
  content:  内容(可选内容为){ text | id | img | url | iframe }
    width:    内容宽度
   height:    内容高度
     drag:  是否可以拖动(ture为是,false为否)
     time:    自动关闭等待的时间,为空是则不自动关闭
   showbg:    [可选参数]设置是否显示遮罩层(0为不显示,1为显示)
  cssName:  [可选参数]附加class名称
 ------------------------------------------------------------------------*/
 //示例:
 //------------------------------------------------------------------------
 //simpleWindown("例子","text:例子","500","400","true","3000","0","exa")
 //------------------------------------------------------------------------
var showWindown = true;
var templateSrc = "http://www.7daysinn.cn"; //设置loading.gif路径
function tipsWindown(title,content,width,height,drag,time,showbg,cssName,backcall) {
    $("#windown-box").remove(); //请除内容
    var width = width>= 950?this.width=950:this.width=width;        //设置最大窗口宽度
    var height = height>= 527?this.height=527:this.height=height;  //设置最大窗口高度
    if(showWindown == true) {
        var simpleWindown_html = new String;
            simpleWindown_html = "<div id=\"windownbg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;z-index: 999901\"></div>";
            simpleWindown_html += "<div id=\"windown-box\">";
            simpleWindown_html += "<div id=\"windown-title\"><h2></h2><span id=\"windown-close\">关闭</span></div>";
            simpleWindown_html += "<div id=\"windown-content-border\"><div id=\"windown-content\"></div></div>"; 
            simpleWindown_html += "</div>";
            $("body").append(simpleWindown_html);
            show = false;
    }
    contentType = content.substring(0,content.indexOf(":"));
    content = content.substring(content.indexOf(":")+1,content.length);
    switch(contentType) {
        case "text":
        $("#windown-content").html(content);
        break;
        case "id":
        $("#windown-content").html($("#"+content+"").html());
        break;
        case "img":
        $("#windown-content").ajaxStart(function() {
            $(this).html("<img src='"+templateSrc+"/images/loading.gif' class='loading' />");
        });
        $.ajax({
            error:function(){
                $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
            },
            success:function(html){
                $("#windown-content").html("<img src="+content+" alt='' />");
            }
        });
        break;
        case "url":
        var content_array=content.split("?");
        $("#windown-content").ajaxStart(function(){
            $(this).html("<img src='"+templateSrc+"/images/loading.gif' class='loading' />");
        });
        $.ajax({
            type:content_array[0],
            url:content_array[1],
            data:content_array[2],
            error:function(){
                $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
            },
            success:function(html){
                $("#windown-content").html(html);
                if(backcall)
                    backcall();
            }
        });
        break;
        case "iframe":
        $("#windown-content").ajaxStart(function(){
            $(this).html("<img src='"+templateSrc+"/images/loading.gif' class='loading' />");
        });
        $.ajax({
            error:function(){
                $("#windown-content").html("<p class='windown-error'>加载数据出错...</p>");
            },
            success:function(html){
                $("#windown-content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+parseInt(height)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
            }
        });
    }
    $("#windown-title h2").html(title);
    if(showbg == "true") {$("#windownbg").show();}else {$("#windownbg").remove();};
    $("#windownbg").animate({opacity:"0.5"},"normal");//设置透明度
    $("#windown-box").show();
    if( height >= 527 ) {
        $("#windown-title").css({width:(parseInt(width)+22)+"px"});
        $("#windown-content").css({width:(parseInt(width)+17)+"px",height:height+"px"});
    }else {
        $("#windown-title").css({width:(parseInt(width)+10)+"px"});
        $("#windown-content").css({width:width+"px",height:height+"px"});
    }
    var    cw = document.documentElement.clientWidth,ch = document.documentElement.clientHeight,est = document.documentElement.scrollTop; 
    var _version = $.browser.version;
    if ( _version == 6.0 ) {
        $("#windown-box").css({left:"50%",top:(parseInt((ch)/2)+est)+"px",marginTop: -((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
    }else {
        $("#windown-box").css({left:"50%",top:"50%",marginTop:-((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
    };
    var Drag_ID = document.getElementById("windown-box"),DragHead = document.getElementById("windown-title");
        
    var moveX = 0,moveY = 0,moveTop,moveLeft = 0,moveable = false;
        if ( _version == 6.0 ) {
            moveTop = est;
        }else {
            moveTop = 0;
        }
    var    sw = Drag_ID.scrollWidth,sh = Drag_ID.scrollHeight;
        DragHead.onmouseover = function(e) {
            if(drag == "true"){DragHead.style.cursor = "move";}else{DragHead.style.cursor = "default";}
        };
        DragHead.onmousedown = function(e) {
        if(drag == "true"){moveable = true;}else{moveable = false;}
        e = window.event?window.event:e;
        var ol = Drag_ID.offsetLeft, ot = Drag_ID.offsetTop-moveTop;
        moveX = e.clientX-ol;
        moveY = e.clientY-ot;
        document.onmousemove = function(e) {
                if (moveable) {
                e = window.event?window.event:e;
                var x = e.clientX - moveX;
                var y = e.clientY - moveY;
                    if ( x > 0 &&( x + sw < cw) && y > 0 && (y + sh < ch) ) {
                        Drag_ID.style.left = x + "px";
                        Drag_ID.style.top = parseInt(y+moveTop) + "px";
                        Drag_ID.style.margin = "auto";
                        }
                    }
                }
        document.onmouseup = function () {moveable = false;};
        Drag_ID.onselectstart = function(e){return false;}
    }
    $("#windown-content").attr("class","windown-"+cssName);
    if( time == "" || typeof(time) == "undefined") {
        $("#windown-close").click(function() {
            showselect('t123_')
            $("#windownbg").remove();
            $("#windown-box").fadeOut("slow",function(){$(this).remove();});
        });
    }else { 
        setTimeout(closeWindown,time);
    }
    hideselect('t123_');
}
var closeWindown = function() {
    showselect('t123_');
    $("#windownbg").remove();
    $("#windown-box").fadeOut("slow",function(){$(this).remove();});
}
function hideselect(per)
{
    var _version = $.browser.version;
    if ( _version == 6.0 ) {
        $("select",document).each(function(){
            if($(this).attr('name'))
            {
                if($(this).attr('name').substring(0,5)==per)
                {
                    name = $(this).attr('name').substring(5);
                    $(this).attr('name',name);
                    $(this).css('display','');
                }
                if($(this).css('display')!='none')
                {
                    name = per+$(this).attr('name');
                    $(this).attr('name',name);
                }
                $(this).css('display','none');
            }
        });
    }
}
function showselect(per)
{
    var _version = $.browser.version;
    if ( _version == 6.0 ) {
        $("select",document).each(function(){
            if($(this).attr('name'))
            {
                if($(this).attr('name').substring(0,5)==per)
                {
                    name = $(this).attr('name').substring(5);
                    $(this).attr('name',name);
                    $(this).css('display','');
                }
            }
        });
    }
}
---------------------------style.css----------------------------------
<style type="text/css">

.mainlist{padding:10px;}
.mainlist div {margin:0 5px 0 0;font-family:"宋体";font-size:12px;font-weight:400;color:#ddd;}
.btnbox{text-align:center;height:30px;padding-top:10px;background:#ECF9FF;}
#windownbg{display:none;position:absolute;width:100%;height:100%;background:#000;top:0;left:0;}
#windown-box{position:fixed;_position:absolute;border:5px solid #E9F3FD;background:#FFF;text-align:left;}
#windown-title{position:relative;height:30px;border:1px solid #A6C9E1;overflow:hidden;background:url(/images/tipbg.png) 0 0 repeat-x;}
#windown-title h2{position:relative;left:10px;top:5px;font-size:14px;color:#666;}
#windown-close{position:absolute;right:10px;top:8px;width:10px;height:16px;text-indent:-10em;overflow:hidden;background:url(/images/tipbg.png) 100% -49px no-repeat;cursor:pointer;}
#windown-content-border{position:relative;top:-1px;border:1px solid #A6C9E1;padding:5px 0 5px 5px;}
#windown-content img,#windown-content iframe{display:block;}
#windown-content .loading{position:absolute;left:50%;top:50%;margin-left:-8px;margin-top:-8px;}
</style>

---------------------------------html------------------------------
<script type="text/javascript">
    /*
    *弹出本页指定ID的内容于窗口
    *id 指定的元素的id
    *title:    window弹出窗的标题
    *width:    窗口的宽,height:窗口的高
    */
    function showTipsWindown(title, id, width, height) {
        tipsWindown(title, "id:" + id, width, height, "true", "", "true", id);
    }

    function confirmTerm(s) {
        parent.closeWindown();
        if (s == 1) {
            parent.document.getElementById("isread").checked = true;
        }
    }

//弹出层调用
    function popTips() {
        showTipsWindown("jQuery弹出层", 'simTestContent', 600, 255);
        $("#isread").attr("checked", false);
    }
</script>

<div style="display:none;">
<div id="simTestContent" class="simScrollCont">
    <div class="mainlist" >
        <div style="overflow:auto; overflow-x:hidden; height:240px; ">
                <li><span>?</span><a href="#" target="_blank">javascript弹出层插件可自定义js弹出层动画特效</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery弹出层鼠标点击弹出层可浮动在屏幕滚动</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery弹出层特效animate制作类似flash动画效果弹出层</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层 点击按钮弹出层兼容IE和firefox浏览器</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件 鼠标点击文字获取标题弹出层内容信息</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件 ThickBox 多功能弹出层插件支持图片、ajax、内嵌内容弹等</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件FancyBox弹出层演示支持图片、文章内容、flash swf弹出层等</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery弹出层鼠标点击弹出层可浮动在屏幕滚动</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery弹出层特效animate制作类似flash动画效果弹出层</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层 点击按钮弹出层兼容IE和firefox浏览器</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件 鼠标点击文字获取标题弹出层内容信息</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件 ThickBox 多功能弹出层插件支持图片、ajax、内嵌内容弹等</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件FancyBox弹出层演示支持图片、文章内容、flash swf弹出层等</a></li>
                <li><span>?</span><a href="#" target="_blank">javascript弹出层插件可自定义js弹出层动画特效</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery弹出层鼠标点击弹出层可浮动在屏幕滚动</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery弹出层特效animate制作类似flash动画效果弹出层</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层 点击按钮弹出层兼容IE和firefox浏览器</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件 鼠标点击文字获取标题弹出层内容信息</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件 ThickBox 多功能弹出层插件支持图片、ajax、内嵌内容弹等</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件FancyBox弹出层演示支持图片、文章内容、flash swf弹出层等</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery弹出层鼠标点击弹出层可浮动在屏幕滚动</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery弹出层特效animate制作类似flash动画效果弹出层</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层 点击按钮弹出层兼容IE和firefox浏览器</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件 鼠标点击文字获取标题弹出层内容信息</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件 ThickBox 多功能弹出层插件支持图片、ajax、内嵌内容弹等</a></li>
                <li><span>?</span><a href="#" target="_blank">jquery 弹出层插件FancyBox弹出层演示支持图片、文章内容、flash swf弹出层等</a></li>
</div>
     </div>
        </div><!--simTestContent end-->
    </div>

版权声明:本文版权归作者所有,遵循 CC 4.0 BY-SA 许可协议, 转载请注明原文链接
https://segmentfault.com/a/1190000005932333

网站的肥胖症危机(节译版) - 编程思维

1、大多数网站的主要内容是文本,更准确地说,是简短的文本。 文本本身并不大,但是展示它们的网页,正变得越来越大。Twitter展示单条评论(140个字符)的页面,超过900KB。Medium的一篇文章大约400个词,页面大小是1.2MB。 如果这种趋势持续下去,2020年,网页的体积平均将超过5MB,比一本俄罗斯长篇小

前端面试大全 - 编程思维

HTML面试题 1.XHTML和HTML有什么区别 HTML是一种基本的WEB网页设计语言,XHTML是一个基于XML的置标语言最主要的不同: XHTML 元素必须被正确地嵌套。 XHTML 元素必须被关闭。 标签名必须用小写字母。 XHTML 文档必须拥有根元素。 2.前端页面有哪三层构成,分别是什么?作用是什

非阻塞的异步 io - 编程思维

node - 非阻塞的异步 IO 每当我们提起 node.js 时总会脱口而出 事件驱动、非阻塞I/O 和 单线程,所以我总结了以下几点对这三项概念的阐述,不一定正确仅仅代表个人观点。 单线程 当一个应用程序运行时会产生一个主进程,它与其他并行执行的应用程序一起竟争计算机系统资源,是管理和分配现有所占据资源的基本单位。

css float nine rules - 编程思维

注:本文是对众多博客的学习和总结,可能存在理解错误。请带着怀疑的眼光,同时如果有错误希望能指出。如果你喜欢我的文章,可以关注我的私人博客:http://blog-qeesung.rhcloud.com/ 入门前端也算是有三个月之久了,发现Float这个属性一直都很迷惑,只是知道一些简单的浮动规则,并没有深入去学习,一旦

【译】html表单高级样式 - 编程思维

系列文章说明 原文 在本文中,我们将了解如何在HTML表单上使用CSS,为那些难于自定义的表单组件加以样式。如前文所述,文本框和按钮很适合使用CSS,而现在我们得来探索HTML表单样式的那些坑了。 在进一步讨论前,先回顾下两种HTML表单组件: 比较糟糕的一些元素只能使用很少的样式,而且得依赖一些复杂的技巧,偶尔还得

织梦本地调试好的网站怎么上传到服务器 - 编程思维

1/ 织梦在本地调试好后,进入本地网站的后台:点击 “系统-----数据库备份/还原”, 织梦本地调试好的网站怎么 上传到服务器。 2/ 把本地程序根目录的install这个文件夹删除。 重新拷贝一个没有安装过织梦程序里面的install文件夹放到本地程序根目录下。 3/ 把本地织梦程序上传到服务器解压后,

纯css实现扁平化风格开关按钮 - 编程思维

开关样式预览图 前言 最近在基于bootstrap框架开发一个网站,在填写表单一项需要用户填写是否选择某一选项,本来想引用bootstrap框架自带的一个按钮插件,结果在引用js的时候总是出错,就找了找资源,用纯css实现这个按钮开关的功能。 具体代码过程 话不多说,直接上代码实现! html代码部分 <div

关于浮动与清除浮动,你应该知道的 - 编程思维

我在做页面布局的时候,多多少少总会受到来自浮动的困扰,因此专门通过实践来总结一下浮动与清除浮动。 首先总结几个基础的概念: 浮动:设置浮动的元素会脱离文档流,不会影响块元素的布局,但是会影响内联元素的排列[通常是文本]; 文档流:在文档流中,块元素会单个元素独占一行 接下来我们通过实际演示来看看关于浮动的那些事儿。 下