职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 631|回复: 9

JQuery遮罩层

[复制链接]
gz-vps 发表于 2011-8-27 10:50 | 显示全部楼层 |阅读模式
以下是截图:    ......
Javascript......
BoneWG写道 J......
谢谢你的建议......
以下这个更好 Jav......
document.d......
int08h写道 d......
楼主,您这截图.........
(*^__^*)嘻嘻......
楼主v5,我经常用$......


以下是截图 :




代码 :

Js代码  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
<HTML>   
<HEAD>   
  <TITLE>遮罩层效果</TITLE>   
    <style type="text/css">   
        .mask {   
            padding : 0px ;   
            margin : 0px ;   
            background : #555 ;   
            position : absolute ;   
        }   
    </style>   
  
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>   
    <script type="text/javascript">   
        $(function(){   
            Mask.load() ;   
        }) ;   
  
        var Mask = function(){   
            function load(){   
                var jq = _render() ;   
                $("body").click(function(){   
                    unload(jq) ;   
                }) ;   
            } ;   
            function unload(jq){   
                jq.remove() ;   
            } ;   
            function _render(){   
                var _div = $("<div></div>")   
                                .addClass("mask")   
                                .appendTo("body") ;   
                var _css = _getCss() ;   
                _div   
                    .css(_css)   
                    .fadeIn() ;   
                return _div ;   
            } ;   
            function _getCss(){   
                var css = {   
                    display : "none" ,   
                    top : 0 +  "px" ,   
                    left : 0 + "px" ,   
                    width : document.documentElement.clientWidth + "px" ,   
                    height : document.documentElement.clientHeight + "px" ,   
                    zIndex : 9999 ,   
                    opacity : 0.6   
                } ;   
                return css ;   
            } ;   
            return {   
                load : load ,   
                unload : unload   
            } ;   
        }() ;   
    </script>   
</HEAD>   
  
<BODY>   
     
</BODY>   
</HTML>  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD>
  <TITLE>遮罩层效果</TITLE>
        <style type="text/css">
                .mask {
                        padding : 0px ;
                        margin : 0px ;
                        background : #555 ;
                        position : absolute ;
                }
        </style>

        <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript">
                $(function(){
                        Mask.load() ;
                }) ;

                var Mask = function(){
                        function load(){
                                var jq = _render() ;
                                $("body").click(function(){
                                        unload(jq) ;
                                }) ;
                        } ;
                        function unload(jq){
                                jq.remove() ;
                        } ;
                        function _render(){
                                var _div = $("<div></div>")
                                                                .addClass("mask")
                                                                .appendTo("body") ;
                                var _css = _getCss() ;
                                _div
                                        .css(_css)
                                        .fadeIn() ;
                                return _div ;
                        } ;
                        function _getCss(){
                                var css = {
                                        display : "none" ,
                                        top : 0 +  "px" ,
                                        left : 0 + "px" ,
                                        width : document.documentElement.clientWidth + "px" ,
                                        height : document.documentElement.clientHeight + "px" ,
                                        zIndex : 9999 ,
                                        opacity : 0.6
                                } ;
                                return css ;
                        } ;
                        return {
                                load : load ,
                                unload : unload
                        } ;
                }() ;
        </script>
</HEAD>

<BODY>
  
</BODY>
</HTML>
  

hxy 发表于 2011-8-27 10:50 | 显示全部楼层
Javascript代码  
$(function(){   
    $('<div></div>',{   
        id:'mask',   
        css:{   
            width(document).width(),   
            height(document).height(),   
            position:'absolute',   
            background:'#000',   
            left:0,   
            top:0   
        }   
    }).appendTo('body').fadeTo('fast',0.6).click(function(){$(this).fadeOut()})   
})  

$(function(){
        $('<div></div>',{
                id:'mask',
                css:{
                        width(document).width(),
                        height(document).height(),
                        position:'absolute',
                        background:'#000',
                        left:0,
                        top:0
                }
        }).appendTo('body').fadeTo('fast',0.6).click(function(){$(this).fadeOut()})
})


天上智喜 发表于 2011-8-27 10:51 | 显示全部楼层
BoneWG 写道
Javascript代码  
$(function(){   
    $('<div></div>',{   
        id:'mask',   
        css:{   
            width(document).width(),   
            height(document).height(),   
            position:'absolute',   
            background:'#000',   
            left:0,   
            top:0   
        }   
    }).appendTo('body').fadeTo('fast',0.6).click(function(){$(this).fadeOut()})   
})  

$(function(){
        $('<div></div>',{
                id:'mask',
                css:{
                        width(document).width(),
                        height(document).height(),
                        position:'absolute',
                        background:'#000',
                        left:0,
                        top:0
                }
        }).appendTo('body').fadeTo('fast',0.6).click(function(){$(this).fadeOut()})
})

无法运行的话请使用jquery1.4以上版本,或者前往http://yu123.me/2010/12/jquery-ad-plugins/查看jquery分体广告插件详细介绍

紫衿 发表于 2011-8-27 10:51 | 显示全部楼层
谢谢你的建议

木已 发表于 2011-8-27 10:51 | 显示全部楼层
以下这个更好
Java代码  
$.showad=function(src,width,height,num,top,distance){   
    var i,m,l,t;   
    var dw=width/num;   
    height=height/2;   
    distance=distance/2;   
    var left=($(document).width()-width)/(num+1);   
    var leftl=left*(num+1)/2;   
    var $l=new Array();   
    var $t=new Array();   
    $('html,body').animate({scrollTop: 0});   
    $('<div></div>',{   
        id:'hBg',   
        css:{   
            width:'100%',   
            height(document).height(),   
            background:'#000',   
            display:'none',   
            position:'absolute',   
            left:0,   
            top:0,   
            zIndex:998  
        }   
    }).appendTo('body').fadeTo("slow", 0.8,function(){   
        for(i=0;i<2;i++){   
            for(m=0;m<num;m++){   
                l=left*(m+1)+dw*m;   
                t=top-distance+i*(height+2*distance);   
                $('<div></div>',{   
                    id:'adb'+(m+i*num),   
                    width:dw,   
                    height:height,   
                    css:{   
                        position:'absolute',   
                        background:'#000 url(\''+src+'\') no-repeat '+m*(-dw)+'px '+(-i*height)+'px',   
                        display:'none',   
                        zIndex:'999',   
                        left:l,   
                        top:t   
                    }   
                }).appendTo('body').animate({left:leftl+dw*m,top:top+height*i,opacity:'show'},'slow');   
                $l.push(l);   
                $t.push(t);   
            }   
        }   
    }).click(function(){   
        num=num*2;   
        for(i=0;i<num;i++){   
            $('#adb'+i).stop().animate({leftl[i],topt[i],opacity:'hide'},'1000',function(){   
                $(this).remove();   
            });   
        }   
        $(this).remove();   
    })   
}  

$.showad=function(src,width,height,num,top,distance){
        var i,m,l,t;
        var dw=width/num;
        height=height/2;
        distance=distance/2;
        var left=($(document).width()-width)/(num+1);
        var leftl=left*(num+1)/2;
        var $l=new Array();
        var $t=new Array();
        $('html,body').animate({scrollTop: 0});
        $('<div></div>',{
                id:'hBg',
                css:{
                        width:'100%',
                        height(document).height(),
                        background:'#000',
                        display:'none',
                        position:'absolute',
                        left:0,
                        top:0,
                        zIndex:998
                }
        }).appendTo('body').fadeTo("slow", 0.8,function(){
                for(i=0;i<2;i++){
                        for(m=0;m<num;m++){
                                l=left*(m+1)+dw*m;
                                t=top-distance+i*(height+2*distance);
                                $('<div></div>',{
                                        id:'adb'+(m+i*num),
                                        width:dw,
                                        height:height,
                                        css:{
                                                position:'absolute',
                                                background:'#000 url(\''+src+'\') no-repeat '+m*(-dw)+'px '+(-i*height)+'px',
                                                display:'none',
                                                zIndex:'999',
                                                left:l,
                                                top:t
                                        }
                                }).appendTo('body').animate({left:leftl+dw*m,top:top+height*i,opacity:'show'},'slow');
                                $l.push(l);
                                $t.push(t);
                        }
                }
        }).click(function(){
                num=num*2;
                for(i=0;i<num;i++){
                        $('#adb'+i).stop().animate({leftl[i],topt[i],opacity:'hide'},'1000',function(){
                                $(this).remove();
                        });
                }
                $(this).remove();
        })
}


北大青鸟 发表于 2011-8-27 10:51 | 显示全部楼层
document.documentElement.clientWidth改成$(window).width()吧,jQuery还是有其他的考虑的
这截图太生猛了……

醉倚西风 发表于 2011-8-27 10:51 | 显示全部楼层
int08h 写道
document.documentElement.clientWidth改成$(window).width()吧,jQuery还是有其他的考虑的
这截图太生猛了……


呵呵见笑了!


 楼主| gz-vps 发表于 2011-8-27 10:51 | 显示全部楼层
楼主,您这截图...
太幽默了。注册2年第一次回帖。

秋秋 发表于 2011-8-27 10:52 | 显示全部楼层
(*^__^*) 嘻嘻……

fl 发表于 2011-8-27 10:52 | 显示全部楼层
楼主v5,我经常用$.blockUI()解决这个问题!!
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-4-29 16:22 , Processed in 0.156197 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表