JavaScript相册单图放大预览第二版(js控制图片上下居中)
2017-08-11 19:43
489 查看
源码下载
CSS
.zoomify img{ cursor: pointer; cursor:url(/Images/icon/zoombig.cur),pointer;cursor: -webkit-zoom-in; cursor: zoom-in;}
.zoomify-shadow { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; display: none; z-index: 1500; background-color: #000; background: rgba(0, 0, 0 , .8); filter: alpha(opacity=80);opacity:0.8; -moz-opacity:0.8; }
.zoomify-shaimg{position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; display: none; z-index: 1501; overflow:scroll;}
.zoomify-shaimg img{ display: block; margin:0 auto; }
.zoomify-shaimg.zoomout{cursor: pointer;cursor:url(/Images/icon/zoommin.cur),pointer; cursor: -webkit-zoom-out; cursor: zoom-out;}
.zoomify-shaimg.zoomin{cursor: pointer; cursor:url(/Images/icon/zoombig.cur),pointer;cursor: -webkit-zoom-in; cursor: zoom-in; }
HTML
在需要实现的模块中加入class="zoomify"
<div class="zoomify">
<img src="images/33a.bmp">
<img src="images/33c.bmp">
<img src="images/33d.bmp">
</div>
body中加入zoomify html
<div class="zoomify-shadow">
</div>
<div class="zoomify-shaimg zoomout">
<img src="" /></div>
JS
$(function() {
$(".zoomify-shadow,.zoomify-shaimg").click(function() {
$(".zoomify-shadow,.zoomify-shaimg").css("display", "none");
$(document.body).css({ "overflow-x": "auto", "overflow-y": "auto" });
});
$(".zoomify img").live("click", function() {
$(".zoomify-shadow").css("width", $(window).width()).css("height", $(window).height());
$(".zoomify-shaimg").css("width", $(window).width()).css("height", $(window).height());
$(".zoomify-shaimg img").attr("src", $(this).attr("src"));
var _image = new Image();
_image.src = $(this).attr("src");
if (_image.height <= $(window).height()) {
$(".zoomify-shaimg img").css("margin-top", ($(window).height() - _image.height) / 2).css("margin-bottom", ($(window).height() - _image.height) / 2);
$(".zoomify-shaimg").css("overflow-y", "hidden");
} else {
$(".zoomify-shaimg img").css("margin-top", 30).css("margin-bottom", 30);
$(".zoomify-shaimg").css("overflow-y", "auto");
$(document.body).css({ "overflow-x": "hidden", "overflow-y": "hidden" });
$(".zoomify-shadow").css("width", $(window).width()).css("height", $(window).height());
$(".zoomify-shaimg").css("width", $(window).width()).css("height", $(window).height());
}
if (_image.width <= $(window).width()) {
$(".zoomify-shaimg").css("overflow-x", "hidden");
$(".zoomify-shadow").css("width", $(window).width()).css("height", $(window).height());
$(".zoomify-shaimg").css("width", $(window).width()).css("height", $(window).height());
} else {
$(".zoomify-shaimg").css("overflow-x", "auto");
}
$(".zoomify-shadow,.zoomify-shaimg").css("display", "block");
});
$(".zoomify img,.zoomify-shaimg").live("mousedown", function(e) { e.preventDefault(); });
});
CSS
.zoomify img{ cursor: pointer; cursor:url(/Images/icon/zoombig.cur),pointer;cursor: -webkit-zoom-in; cursor: zoom-in;}
.zoomify-shadow { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; display: none; z-index: 1500; background-color: #000; background: rgba(0, 0, 0 , .8); filter: alpha(opacity=80);opacity:0.8; -moz-opacity:0.8; }
.zoomify-shaimg{position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; display: none; z-index: 1501; overflow:scroll;}
.zoomify-shaimg img{ display: block; margin:0 auto; }
.zoomify-shaimg.zoomout{cursor: pointer;cursor:url(/Images/icon/zoommin.cur),pointer; cursor: -webkit-zoom-out; cursor: zoom-out;}
.zoomify-shaimg.zoomin{cursor: pointer; cursor:url(/Images/icon/zoombig.cur),pointer;cursor: -webkit-zoom-in; cursor: zoom-in; }
HTML
在需要实现的模块中加入class="zoomify"
<div class="zoomify">
<img src="images/33a.bmp">
<img src="images/33c.bmp">
<img src="images/33d.bmp">
</div>
body中加入zoomify html
<div class="zoomify-shadow">
</div>
<div class="zoomify-shaimg zoomout">
<img src="" /></div>
JS
$(function() {
$(".zoomify-shadow,.zoomify-shaimg").click(function() {
$(".zoomify-shadow,.zoomify-shaimg").css("display", "none");
$(document.body).css({ "overflow-x": "auto", "overflow-y": "auto" });
});
$(".zoomify img").live("click", function() {
$(".zoomify-shadow").css("width", $(window).width()).css("height", $(window).height());
$(".zoomify-shaimg").css("width", $(window).width()).css("height", $(window).height());
$(".zoomify-shaimg img").attr("src", $(this).attr("src"));
var _image = new Image();
_image.src = $(this).attr("src");
if (_image.height <= $(window).height()) {
$(".zoomify-shaimg img").css("margin-top", ($(window).height() - _image.height) / 2).css("margin-bottom", ($(window).height() - _image.height) / 2);
$(".zoomify-shaimg").css("overflow-y", "hidden");
} else {
$(".zoomify-shaimg img").css("margin-top", 30).css("margin-bottom", 30);
$(".zoomify-shaimg").css("overflow-y", "auto");
$(document.body).css({ "overflow-x": "hidden", "overflow-y": "hidden" });
$(".zoomify-shadow").css("width", $(window).width()).css("height", $(window).height());
$(".zoomify-shaimg").css("width", $(window).width()).css("height", $(window).height());
}
if (_image.width <= $(window).width()) {
$(".zoomify-shaimg").css("overflow-x", "hidden");
$(".zoomify-shadow").css("width", $(window).width()).css("height", $(window).height());
$(".zoomify-shaimg").css("width", $(window).width()).css("height", $(window).height());
} else {
$(".zoomify-shaimg").css("overflow-x", "auto");
}
$(".zoomify-shadow,.zoomify-shaimg").css("display", "block");
});
$(".zoomify img,.zoomify-shaimg").live("mousedown", function(e) { e.preventDefault(); });
});
相关文章推荐
- js实现简单的动画(4个按钮控制图片上下左右移动)
- neatbeans用js实现图片预览上传(自动控制图片大小)
- JavaScript进阶(八)JS实现图片预览并导入服务器功能
- JS实现用键盘控制DIV上下左右+放大缩小与变色
- JavaScript相册单图放大预览
- JS网页图片查看器-可控制图片放大缩小还原移动效果
- js控制图片缩放、水平和垂直方向居中对齐
- html和js图片上下居中的两种方法
- JS&RE 控制图片显示大小, 弹出窗口自适应大小,自居中, 结合UBB与正则使用 By Stabx
- 纯JS实现图片预览与等比例缩放和居中
- JavaScript + CSS 实现图片放大预览效果
- 模仿微信朋友圈 仿微信js-sdk wx.previewImage javascript实现,支持图片预览,滑动切换,双指缩放,图片缓存 h5 html5 js
- js控制图片上传预览,使用三方插件+名称显示和控件非display:none隐藏
- 在线图片上传、预览、裁切、放大、缩小之 cropbox.js 的应用
- JS实现控制图片放大缩小代码
- JS网页图片查看器-可控制图片放大缩小还原移动效果
- [js/jquery]移动端手势拖动,放大,缩小预览图片
- jquery插件jquery.LightBox.js之点击放大图片并左右点击切换图片(仿相册插件)
- Javascript/js兼容各个浏览器的本地图片上传即时预览效果
- JS放大镜,JavaScript图片放大代码