栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

jQuery实现点击查看大图并以弹框的形式居中

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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_img img{width:100%;height:100%;}
.bigImg{display:none;width:300px;height:300px;z-index:999;position:absolute;left:50%;margin-top:-150px;margin-left:-150px;}
.bigImg img{width:100%;height:100%;}
.close{display:none;width:20px;height:20px;border-radius:100%;border:1px solid #ccc;text-align:center;cursor:pointer;position:absolute;right:10px;top:10px;z-index:999;color:#fff}
li{height:300px;}








x

  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
  • 111
1
2
3
var $height=$(window).height();
$(".tab_bg").height($height);
function imgEnlarge(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(){return false});
var top1=$(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实现点击查看大图并以弹框的形式居中,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/95036.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号