欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jquery开发查看大图功能实现代码

程序员文章站 2024-02-18 21:09:46
代码如下: /*查看大图*/ var screenheight = $(window).height(); var screenwidth = $(window).width(); var loa...

代码如下:


/*查看大图*/
var screenheight = $(window).height();
var screenwidth = $(window).width();
var loadcss = function(){
var screenwidth = $(window).width();
var screenheight = $(window).height();
$("p.lookbigpicture").css({"left":screenwidth*0.2,"top":screenheight*0.15+$(document).scrolltop(),
"width":screenwidth*0.6,"height":screenheight*0.7});
$("img.bigimg").css({"max-width":(screenwidth*0.6 - 30),"max-height":screenheight*0.7-40});
$("img.bigimg").load(function(){
$("img.bigimg").css("top",(screenheight*0.7 - 30 - $("img.bigimg").height())*0.5 + 30);
});
$("img.bigimg").css("top",(screenheight*0.7 - 30 - $("img.bigimg").height())*0.5 + 30);
$.log("$(document).height():"+$(document).height());
};
$("a#bigpic").click(function(){
$.log("screenheight:"+screenheight+"screenwidth:"+screenwidth);
str = $("img[img-size]").attr("src");
$("body").append("<p class='grey'></p>");//灰色底层
$("body").append("<p class='lookbigpicture'><span class='protopic'><a z-index='20001' target='_blank' href='"+str+"'>查看原图</a></span><a href='javascript:;' class='bigpicclose' title='关闭'>×</a><img class='bigimg' src='"+str+"'/></p>");
$("p.grey").css( "height",$(document).height());
loadcss();
$("body").css({overflow:"hidden"}); //禁用滚动条
});
$("body").delegate("p.grey,a.bigpicclose","click",function(){
$("body").css({overflow:"visible"}); //恢复滚动条
$("p.lookbigpicture").remove();
$("p.grey").remove();
});
//当窗口大小改变时
$(window).resize(function () {
loadcss();
});


. 代码如下:


/***遮罩层****/
.grey {
background: #000;
display: block;
z-index: 1000;
width: 100%;
position: absolute;
filter: alpha(opacity : 50);
opacity: 0.5;
top: 0;
left: 0;
top: 0;
}

.lookbigpicture {
border: #000 solid 1px;
position: absolute;
z-index: 2000;
text-align: center;
background: black;
}

.bigimg {
margin-left: auto;
margin-right: auto;
position: relative;
}

.bigpicclose {
position: absolute;
width: 36px;
height: 36px;
font-size: 0;
z-index: 20001;
top: -18px;
right: -18px;
background:
url("https://img.t.sinajs.cn/t5/style/images/layer/multipic_ico.png?id=20131018174500")
0 0 no-repeat;
}

.lookbigicn {
display: inline-block;
width: 12px;
height: 12px;
background:
url("https://img.t.sinajs.cn/t5/style/images/common/icon.png?id=1383027536816")
-175px -25px no-repeat;
vertical-align: -2px;
margin-left: 20px;
}

.w_ico12 {
display: inline-block;
width: 12px;
height: 12px;
background:
url("https://img.t.sinajs.cn/t5/style/images/common/icon.png?id=1383027536816")
-175px 0px no-repeat;
vertical-align: -2px;
}

.protopic {
position: absolute;
display: inline-block;
height: 30px;
top: 10px;
right: 50px;
overflow: hidden;
cursor: pointer;
color: #f8f8f8;
text-shadow: 0 1px 0 rgba(0, 0, 0, .5);
}


. 代码如下:


<p pic-choice style="display: none;">
<em class="w_ico12"></em><a href="javascript:;" id="hidepic">收起</a>
<em class="lookbigicn"></em><a href="javascript:;" id="bigpic">查看大图</a>
</p>