复制代码 代码如下:
jsFiddleRun again Edit this fiddle Result HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312" />
<title>放大镜</title>
<style>
img{ vertical-align:bottom;}
.mod_zoom{ overflow:hidden; zoom:1;}
.mod_zoom .p1 { float:left; position:relative; height:350px; width:350px; margin-right:5px; }
.mod_zoom .p1 .mask{ position:absolute; left:0; top:0; width:175px; height:175px; background-color:#fede4f; opacity:0.3; filter: alpha(opacity=30); display:none; }
.mod_zoom .p2{ position:relative; width:400px; height:400px; overflow:hidden; display:none;}
.mod_zoom .p2 .img{ position:absolute; left:0; top:0;}
.mod_zoom .ph{width:100%; height:350px; position:absolute; top:0; left:0; cursor:crosshair;
/*background-color:red*/
/*如果给它绑定事件处理函数,IE中不设置background-color属性就不触发事件*/ }
</style>
</head>
<body>
<div>
<div class="mod_zoom">
<div class="p1" id="p1">
<img src="/UploadFiles/2021-04-02/b350e77e-fc74-4173-81b5-dfe54f425ef6.jpg"><span class="mask" id="m"></span>
<span class="ph" id="eventproxy"></span>
</div>
<div class="p2" id="p2">
<img src="/UploadFiles/2021-04-02/b350e77e-fc74-4173-81b5-dfe54f425ef6.jpg"></div>
</div>
</div>
<script>
function PhotoZoomer(elements){
this.mask = elements.mask; //蒙版
this.container = elements.container //原图容器
this.originimg = elements.originimg; //原图
this.eventproxy = elements.eventproxy;
this.bigContainer = elements.bigContainer; //大图容器
this.bigimg = elements.bigimg; //大图
this.visible = false;
this._bind();
}
PhotoZoomer.prototype = {
display: function(style){
var self = this;
self.mask.style.display = style;
self.bigContainer.style.display = style;
},
//计算放大蒙版位置
zoom: function(clientX, clientY){
var self = this,
//位置比例
rate = {},
//放大蒙版最大活动范围
maxrange = {
offsetLeft: self.container.offsetWidth - self.mask.offsetWidth,
offsetTop: self.container.offsetHeight - self.mask.offsetHeight
},
//mask left
left = clientX - self.container.offsetLeft - self.mask.offsetWidth/2,
//mask top
top = clientY - self.container.offsetTop - self.mask.offsetHeight/2;
if(left < 0) {
left = 0;
}else if(left> maxrange.offsetLeft) {
left = maxrange.offsetLeft;
}
if(top < 0) {
top = 0;
}else if(top > maxrange.offsetTop){
top = maxrange.offsetTop;
}
//alert(maxrange.offsetTop);
rate.left = left / maxrange.offsetLeft;
rate.top = top / maxrange.offsetTop;
self.mask.style.left = left + 'px';
self.mask.style.top = top + 'px';
self.bigimg.style.left = -rate.left * (self.bigimg.offsetWidth - self.bigContainer.offsetWidth) + "px";
self.bigimg.style.top = -rate.top * (self.bigimg.offsetHeight - self.bigContainer.offsetHeight) + "px";
},
_bind: function(){
var self = this;
self.container.onmouseover = function(e){
e = e || window.event;
var target = e.targe || e.srcElement;
self.display("block");
this.visible = true;
};
self.container.onmouseout = function(e){
e = e || window.event;
var target = e.targe || e.srcElement;
self.display("none");
this.visible = false;
};
self.container.onmousemove = function(e){
e = e || window.event;
if(!this.visible )return;//防止元素大小计算错误
self.zoom(e.clientX, e.clientY);
};
}
};
function get(id){
return document.getElementById(id)
}
var elements = {
mask: get("m"),
container: get("p1"),
originimg: get("z1"),
bigContainer: get("p2"),
bigimg: get("z2"),
eventproxy: get("eventproxy")
};
var zoomer = new PhotoZoomer(elements);
// alert(elements.container.offsetParent.tagName)
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312" />
<title>放大镜</title>
<style>
img{ vertical-align:bottom;}
.mod_zoom{ overflow:hidden; zoom:1;}
.mod_zoom .p1 { float:left; position:relative; height:350px; width:350px; margin-right:5px; }
.mod_zoom .p1 .mask{ position:absolute; left:0; top:0; width:175px; height:175px; background-color:#fede4f; opacity:0.3; filter: alpha(opacity=30); display:none; }
.mod_zoom .p2{ position:relative; width:400px; height:400px; overflow:hidden; display:none;}
.mod_zoom .p2 .img{ position:absolute; left:0; top:0;}
.mod_zoom .ph{width:100%; height:350px; position:absolute; top:0; left:0; cursor:crosshair;
/*background-color:red*/
/*如果给它绑定事件处理函数,IE中不设置background-color属性就不触发事件*/ }
</style>
</head>
<body>
<div>
<div class="mod_zoom">
<div class="p1" id="p1">
<img src="/UploadFiles/2021-04-02/b350e77e-fc74-4173-81b5-dfe54f425ef6.jpg"><span class="mask" id="m"></span>
<span class="ph" id="eventproxy"></span>
</div>
<div class="p2" id="p2">
<img src="/UploadFiles/2021-04-02/b350e77e-fc74-4173-81b5-dfe54f425ef6.jpg"></div>
</div>
</div>
<script>
function PhotoZoomer(elements){
this.mask = elements.mask; //蒙版
this.container = elements.container //原图容器
this.originimg = elements.originimg; //原图
this.eventproxy = elements.eventproxy;
this.bigContainer = elements.bigContainer; //大图容器
this.bigimg = elements.bigimg; //大图
this.visible = false;
this._bind();
}
PhotoZoomer.prototype = {
display: function(style){
var self = this;
self.mask.style.display = style;
self.bigContainer.style.display = style;
},
//计算放大蒙版位置
zoom: function(clientX, clientY){
var self = this,
//位置比例
rate = {},
//放大蒙版最大活动范围
maxrange = {
offsetLeft: self.container.offsetWidth - self.mask.offsetWidth,
offsetTop: self.container.offsetHeight - self.mask.offsetHeight
},
//mask left
left = clientX - self.container.offsetLeft - self.mask.offsetWidth/2,
//mask top
top = clientY - self.container.offsetTop - self.mask.offsetHeight/2;
if(left < 0) {
left = 0;
}else if(left> maxrange.offsetLeft) {
left = maxrange.offsetLeft;
}
if(top < 0) {
top = 0;
}else if(top > maxrange.offsetTop){
top = maxrange.offsetTop;
}
//alert(maxrange.offsetTop);
rate.left = left / maxrange.offsetLeft;
rate.top = top / maxrange.offsetTop;
self.mask.style.left = left + 'px';
self.mask.style.top = top + 'px';
self.bigimg.style.left = -rate.left * (self.bigimg.offsetWidth - self.bigContainer.offsetWidth) + "px";
self.bigimg.style.top = -rate.top * (self.bigimg.offsetHeight - self.bigContainer.offsetHeight) + "px";
},
_bind: function(){
var self = this;
self.container.onmouseover = function(e){
e = e || window.event;
var target = e.targe || e.srcElement;
self.display("block");
this.visible = true;
};
self.container.onmouseout = function(e){
e = e || window.event;
var target = e.targe || e.srcElement;
self.display("none");
this.visible = false;
};
self.container.onmousemove = function(e){
e = e || window.event;
if(!this.visible )return;//防止元素大小计算错误
self.zoom(e.clientX, e.clientY);
};
}
};
function get(id){
return document.getElementById(id)
}
var elements = {
mask: get("m"),
container: get("p1"),
originimg: get("z1"),
bigContainer: get("p2"),
bigimg: get("z2"),
eventproxy: get("eventproxy")
};
var zoomer = new PhotoZoomer(elements);
// alert(elements.container.offsetParent.tagName)
</script>
</body>
</html>
jsFiddleRun again Edit this fiddle Result HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312" />
<title>放大镜</title>
<style>
img{ vertical-align:bottom;}
.mod_zoom{ overflow:hidden; zoom:1;}
.mod_zoom .p1 { float:left; position:relative; height:350px; width:350px; margin-right:5px; }
.mod_zoom .p1 .mask{ position:absolute; left:0; top:0; width:175px; height:175px; background-color:#fede4f; opacity:0.3; filter: alpha(opacity=30); display:none; }
.mod_zoom .p2{ position:relative; width:400px; height:400px; overflow:hidden; display:none;}
.mod_zoom .p2 .img{ position:absolute; left:0; top:0;}
.mod_zoom .ph{width:100%; height:350px; position:absolute; top:0; left:0; cursor:crosshair;
/*background-color:red*/
/*如果给它绑定事件处理函数,IE中不设置background-color属性就不触发事件*/ }
</style>
</head>
<body>
<div>
<div class="mod_zoom">
<div class="p1" id="p1">
<img src="/UploadFiles/2021-04-02/b350e77e-fc74-4173-81b5-dfe54f425ef6.jpg"><span class="mask" id="m"></span>
<span class="ph" id="eventproxy"></span>
</div>
<div class="p2" id="p2">
<img src="/UploadFiles/2021-04-02/b350e77e-fc74-4173-81b5-dfe54f425ef6.jpg"></div>
</div>
</div>
<script>
function PhotoZoomer(elements){
this.mask = elements.mask; //蒙版
this.container = elements.container //原图容器
this.originimg = elements.originimg; //原图
this.eventproxy = elements.eventproxy;
this.bigContainer = elements.bigContainer; //大图容器
this.bigimg = elements.bigimg; //大图
this.visible = false;
this._bind();
}
PhotoZoomer.prototype = {
display: function(style){
var self = this;
self.mask.style.display = style;
self.bigContainer.style.display = style;
},
//计算放大蒙版位置
zoom: function(clientX, clientY){
var self = this,
//位置比例
rate = {},
//放大蒙版最大活动范围
maxrange = {
offsetLeft: self.container.offsetWidth - self.mask.offsetWidth,
offsetTop: self.container.offsetHeight - self.mask.offsetHeight
},
//mask left
left = clientX - self.container.offsetLeft - self.mask.offsetWidth/2,
//mask top
top = clientY - self.container.offsetTop - self.mask.offsetHeight/2;
if(left < 0) {
left = 0;
}else if(left> maxrange.offsetLeft) {
left = maxrange.offsetLeft;
}
if(top < 0) {
top = 0;
}else if(top > maxrange.offsetTop){
top = maxrange.offsetTop;
}
//alert(maxrange.offsetTop);
rate.left = left / maxrange.offsetLeft;
rate.top = top / maxrange.offsetTop;
self.mask.style.left = left + 'px';
self.mask.style.top = top + 'px';
self.bigimg.style.left = -rate.left * (self.bigimg.offsetWidth - self.bigContainer.offsetWidth) + "px";
self.bigimg.style.top = -rate.top * (self.bigimg.offsetHeight - self.bigContainer.offsetHeight) + "px";
},
_bind: function(){
var self = this;
self.container.onmouseover = function(e){
e = e || window.event;
var target = e.targe || e.srcElement;
self.display("block");
this.visible = true;
};
self.container.onmouseout = function(e){
e = e || window.event;
var target = e.targe || e.srcElement;
self.display("none");
this.visible = false;
};
self.container.onmousemove = function(e){
e = e || window.event;
if(!this.visible )return;//防止元素大小计算错误
self.zoom(e.clientX, e.clientY);
};
}
};
function get(id){
return document.getElementById(id)
}
var elements = {
mask: get("m"),
container: get("p1"),
originimg: get("z1"),
bigContainer: get("p2"),
bigimg: get("z2"),
eventproxy: get("eventproxy")
};
var zoomer = new PhotoZoomer(elements);
// alert(elements.container.offsetParent.tagName)
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312" />
<title>放大镜</title>
<style>
img{ vertical-align:bottom;}
.mod_zoom{ overflow:hidden; zoom:1;}
.mod_zoom .p1 { float:left; position:relative; height:350px; width:350px; margin-right:5px; }
.mod_zoom .p1 .mask{ position:absolute; left:0; top:0; width:175px; height:175px; background-color:#fede4f; opacity:0.3; filter: alpha(opacity=30); display:none; }
.mod_zoom .p2{ position:relative; width:400px; height:400px; overflow:hidden; display:none;}
.mod_zoom .p2 .img{ position:absolute; left:0; top:0;}
.mod_zoom .ph{width:100%; height:350px; position:absolute; top:0; left:0; cursor:crosshair;
/*background-color:red*/
/*如果给它绑定事件处理函数,IE中不设置background-color属性就不触发事件*/ }
</style>
</head>
<body>
<div>
<div class="mod_zoom">
<div class="p1" id="p1">
<img src="/UploadFiles/2021-04-02/b350e77e-fc74-4173-81b5-dfe54f425ef6.jpg"><span class="mask" id="m"></span>
<span class="ph" id="eventproxy"></span>
</div>
<div class="p2" id="p2">
<img src="/UploadFiles/2021-04-02/b350e77e-fc74-4173-81b5-dfe54f425ef6.jpg"></div>
</div>
</div>
<script>
function PhotoZoomer(elements){
this.mask = elements.mask; //蒙版
this.container = elements.container //原图容器
this.originimg = elements.originimg; //原图
this.eventproxy = elements.eventproxy;
this.bigContainer = elements.bigContainer; //大图容器
this.bigimg = elements.bigimg; //大图
this.visible = false;
this._bind();
}
PhotoZoomer.prototype = {
display: function(style){
var self = this;
self.mask.style.display = style;
self.bigContainer.style.display = style;
},
//计算放大蒙版位置
zoom: function(clientX, clientY){
var self = this,
//位置比例
rate = {},
//放大蒙版最大活动范围
maxrange = {
offsetLeft: self.container.offsetWidth - self.mask.offsetWidth,
offsetTop: self.container.offsetHeight - self.mask.offsetHeight
},
//mask left
left = clientX - self.container.offsetLeft - self.mask.offsetWidth/2,
//mask top
top = clientY - self.container.offsetTop - self.mask.offsetHeight/2;
if(left < 0) {
left = 0;
}else if(left> maxrange.offsetLeft) {
left = maxrange.offsetLeft;
}
if(top < 0) {
top = 0;
}else if(top > maxrange.offsetTop){
top = maxrange.offsetTop;
}
//alert(maxrange.offsetTop);
rate.left = left / maxrange.offsetLeft;
rate.top = top / maxrange.offsetTop;
self.mask.style.left = left + 'px';
self.mask.style.top = top + 'px';
self.bigimg.style.left = -rate.left * (self.bigimg.offsetWidth - self.bigContainer.offsetWidth) + "px";
self.bigimg.style.top = -rate.top * (self.bigimg.offsetHeight - self.bigContainer.offsetHeight) + "px";
},
_bind: function(){
var self = this;
self.container.onmouseover = function(e){
e = e || window.event;
var target = e.targe || e.srcElement;
self.display("block");
this.visible = true;
};
self.container.onmouseout = function(e){
e = e || window.event;
var target = e.targe || e.srcElement;
self.display("none");
this.visible = false;
};
self.container.onmousemove = function(e){
e = e || window.event;
if(!this.visible )return;//防止元素大小计算错误
self.zoom(e.clientX, e.clientY);
};
}
};
function get(id){
return document.getElementById(id)
}
var elements = {
mask: get("m"),
container: get("p1"),
originimg: get("z1"),
bigContainer: get("p2"),
bigimg: get("z2"),
eventproxy: get("eventproxy")
};
var zoomer = new PhotoZoomer(elements);
// alert(elements.container.offsetParent.tagName)
</script>
</body>
</html>
标签:
放大镜
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“电子商务网站上的常用的js放大镜效果”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新动态
2024年11月09日
2024年11月09日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]