jQuery实现点击查看大图并以弹框的形式居中
jQuery实现点击查看大图并以弹框的形式居中,实现的关键代码如下所示:
*{margin:0;padding:0;}
.tab_bg{display:none;width:100%;height:100%;background:#282829;z-index:99;position:absolute;}
.tab_img{width:100px;height:100px;margin:20px;}
.tab_imgimg{width:100%;height:100%;}
.bigImg{display:none;width:300px;height:300px;z-index:999;position:absolute;left:50%;margin-top:-150px;margin-left:-150px;}
.bigImgimg{width:100%;height:100%;}
.close{display:none;width:20px;height:20px;border-radius:100%;border:1pxsolid#ccc;text-align:center;cursor:pointer;position:absolute;right:10px;top:10px;z-index:999;color:#fff}
li{height:300px;}
<!DOCTYPEhtml> <html> <headlang="en"> <metacharset="UTF-8"> <title></title> </head> <body> <divclass="tab_bg"> <divclass="close">x</div> </div> <ul> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> <li>111</li> </ul> <table> <tr> <td>1</td> <td><divclass="tab_imgtab_img1"> <imgsrc="2.jpg"alt=""/> </div></td> </tr> <tr> <td>2</td> <td><divclass="tab_imgtab_img2"> <imgsrc="3.jpg"alt=""/> </div></td> </tr> <tr> <td>3</td> <td><divclass="tab_imgtab_img3"> <imgsrc="1.jpg"alt=""/> </div></td> </tr> </table> </body> </html>
var$height=$(window).height();
$(".tab_bg").height($height);
functionimgEnlarge(small){
$(small).on("click",function(){
var$big=document.createElement("div");
$($big).attr("class","bigImg");
$($big).appendTo($("body"));
var$img=document.createElement("img");
$($img).attr("src",$(this).find("img").attr("src"));
$($img).appendTo($big);
$(this).css("display","none");
$(".tab_bg").css("display","block");
$(".close").css("display","block");
$($big).fadeIn();
$(window).bind("scroll",function(){returnfalse});
vartop1=$(window).scrollTop();
$(window).scrollTop(top1);
$(".tab_bg").css("top",top1);
$("body").css("overflow","hidden");
$(".bigImg").css("top",top1+$height/2);
});
$(".close").on("click",function(){
$(this).css("display","none");
$(small).css("display","block");
$(".tab_bg").css("display","none");
$(".bigImg").css("display","none");
$("body").css("overflow","auto");
})
}
$(".tab_img").each(function(){
imgEnlarge($(this));
})
以上所述是小编给大家介绍的jQuery实现点击查看大图并以弹框的形式居中,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下