查看大图功能代码jquery版


Posted in Javascript onNovember 05, 2013
/*查看大图*/ 
var screenheight = $(window).height(); 
var screenwidth = $(window).width(); 
var loadCSS = function(){ 
var screenwidth = $(window).width(); 
var screenheight = $(window).height(); 
$("div.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("<div class='grey'></div>");//灰色底层 
$("body").append("<div 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+"'/></div>"); 
$("div.grey").css( "height",$(document).height()); 
loadCSS(); 
$("body").css({overflow:"hidden"}); //禁用滚动条 
}); 
$("body").delegate("div.grey,a.bigpicclose","click",function(){ 
$("body").css({overflow:"visible"}); //恢复滚动条 
$("div.lookBigPicture").remove(); 
$("div.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("http://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("http://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("http://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>
Javascript 相关文章推荐
jquery自定义函数的多种方法
Jan 09 Javascript
BootStrap网页中代码显示用法详解
Oct 21 Javascript
利用Plupload.js解决大文件上传问题, 带进度条和背景遮罩层
Mar 15 Javascript
JSONP基础知识详解
Mar 19 Javascript
详解vue事件对象、冒泡、阻止默认行为
Mar 20 Javascript
vue实现点击关注后及时更新列表功能
Jun 26 Javascript
js中对象与对象创建方法的各种方法
Feb 27 Javascript
详解javascript设计模式三:代理模式
Mar 25 Javascript
微信小程序的授权实现过程解析
Aug 02 Javascript
vue请求服务器数据后绑定不上的解决方法
Oct 30 Javascript
JavaScript位置参数实现原理及过程解析
Sep 14 Javascript
jQuery zTree如何改变指定节点文本样式
Oct 16 jQuery
使用jquery自定义鼠标样式满足个性需求
Nov 05 #Javascript
iframe子页面获取父页面元素的方法
Nov 05 #Javascript
jquery统计复选框选中示例
Nov 05 #Javascript
jquery实现滑动图片自己测试的例子
Nov 05 #Javascript
用js实现in_array的方法
Nov 05 #Javascript
jquery遍历数组与筛选数组的方法
Nov 05 #Javascript
javascript alert乱码的解决方法
Nov 05 #Javascript
You might like
在PHP中使用与Perl兼容的正则表达式
2006/11/26 PHP
Windows下编译PHP5.4和xdebug全记录
2015/04/03 PHP
你应该知道PHP浮点数知识
2015/05/13 PHP
WordPress网站性能优化指南
2015/11/18 PHP
Yii统计不同类型邮箱数量的方法
2016/10/18 PHP
php常用日期时间函数实例小结
2019/07/04 PHP
JavaScript 常见对象类创建代码与优缺点分析
2009/12/07 Javascript
javaScript 关闭浏览器 (不弹出提示框)
2010/01/31 Javascript
分别用marquee和div+js实现首尾相连循环滚动效果,仅3行代码
2011/09/21 Javascript
JS实现横向拉伸动感伸缩菜单效果代码
2015/09/04 Javascript
js实现文件上传表单域美化特效
2015/11/02 Javascript
基于js里调用函数时,函数名带括号和不带括号的区别
2016/07/28 Javascript
Angular-Ui-Router+ocLazyLoad动态加载脚本示例
2017/03/02 Javascript
vue v-for循环重复数据无法添加问题解决方法【加track-by='索引'】
2019/03/15 Javascript
浅谈Express.js解析Post数据类型的正确姿势
2019/05/30 Javascript
vue中根据时间戳判断对应的时间(今天 昨天 前天)
2019/12/20 Javascript
Vue常用传值方式、父传子、子传父及非父子实例分析
2020/02/24 Javascript
浅谈使用Python内置函数getattr实现分发模式
2018/01/22 Python
pytorch构建网络模型的4种方法
2018/04/13 Python
python主线程捕获子线程的方法
2018/06/17 Python
关于python之字典的嵌套,递归调用方法
2019/01/21 Python
Python实现查找字符串数组最长公共前缀示例
2019/03/27 Python
.img/.hdr格式转.nii格式的操作
2020/07/01 Python
Python实例教程之检索输出月份日历表
2020/12/16 Python
多重CSS背景动画实现方法示例
2014/04/04 HTML / CSS
加拿大时装零售商:Influence U
2018/12/22 全球购物
STAUD官方网站:洛杉矶独有的闲适风格
2019/04/11 全球购物
网络工程师专家职业发展路线
2014/02/14 职场文书
仓库规划计划书
2014/04/28 职场文书
食品流通安全承诺书
2014/05/22 职场文书
普通话宣传标语
2014/06/26 职场文书
全国爱眼日活动总结
2015/02/27 职场文书
2015年学生资助工作总结
2015/05/25 职场文书
仓库管理制度范本
2015/08/04 职场文书
2016年“世界环境日”校园广播稿
2015/12/18 职场文书
Eclipse+Java+Swing+Mysql实现电影购票系统(详细代码)
2022/01/18 Java/Android