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

Jquery实现图片放大镜效果的思路及代码(自写)

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

Jquery实现图片放大镜效果的思路及代码(自写)

网上一大堆限制多,文档也难看懂,而且麻烦~自己写了个。大笑

算法:

第一步:

放大图片的位置=鼠标所在的容器的宽或者高除以容器自身的高度和宽度,求出鼠标在容器中移动的百分比

第二部:

得到百分比之后

x=-(x百分比*图片的宽度-显示容器的宽度/2);

y=-(y百分比*图片的高度-显示容器的高度/2);

两个参数,x和y,就是大图的位置了,后面加了个显示容器的大小/2 是为了保证图片显示在中间。

效果图:
 
代码:
复制代码 代码如下:



商品信息



html,body,img,a,div{
margin: 0px;
padding: 0px;
border: 0px;
font: 12px/150% Arial,Verdana,"宋体";
color: rgb(102, 102, 102);
}

div:after {
clear: both;
content: '.';
height:0;
visibility: hidden;
diplay: block;
}

div {
zoom: 1;
}
.main-body{
text-align: center;
padding: 15px;
}
.head-box{
height: 400px;
border: #CCC 1px solid;
}
.head-box-left{
width: 300px;
height: 390px;

float: left;
padding: 3px;
position: relative;
}
.head-box-right{
width: 500px;
height: 390px;
border: #CCC 1px solid;
float: left;
margin-left: 10px;
}
.goods-max-img{
width: 300px;
height: 300px;
display:block;
border: #CCC 1px solid;
position: relative;
cursor: move;
}
.goods-img-list{
width: 300px;
height: 80px;

margin-top: 10px;
}

.goods-change{
display: block;
float: left;
width: 17px;
height: 54px;
background: url("../web/imgs/goods-change-btn.png");
}
.change-prev{
margin-right: 5px;
margin-left: 2px;
}
.change-prev:HOVER{
background-position: -34px 0px;
}
.change-next{
margin-left: 5px;
background-position: -17px 0px;
}
.change-next:HOVER{
margin-left: 5px;
background-position: -51px 0px;
}

.goods-img-list-box{
width: 250px;
height: 54px;

border: 0px 1px;
float: left;
position: relative;
overflow: hidden;
}
.goods-img-list-box ul{
margin: 0px;
padding: 0px;
position: absolute;
top: 1px;
left: 0px;
width: 500px;
}
.goods-img-list-box ul li{
display: block;
float: left;
width: 50px;
height: 50px;
border: #CCC 1px solid;
margin-left: 3px;
}
.goods-img-list-box ul li a{
display: block;
width: 100%;
height: 100%;
text-decoration: none;
}
.preview-box{
position: absolute;
top: 0px;
width: 500px;
height: 500px;
background-color: white;
border: #CCC 1px solid;
left: 310px;
display: none;
overflow: hidden;
}


























  • 8

  • 7

  • 6

  • 5

  • 3

  • 3

  • 2





















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

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

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