帝王谷资源网 Design By www.wdxyy.com

这个效果并不难,要点是位置和比例设置,

捕获鼠标位置、判断鼠标位置区域、还有onmouseover事件、onmousemove事件、onmouseout事件

设置显示大图的比例,小图上显示的切图比例都要弄准确点,最好是2倍啦,4倍啦。

主要注意宽度,我这里的图片m.jpg是1440X900的....
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD Xhtml 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>放大镜效果</title>
<style type="text/css">
*{margin:0;padding:0;}
#smallimg{width:360px;float:left;position:relative;border:1px solid red;}
#smallimg img{ width:360px;}
#bigimg{float:left;width:400px;height:400px;margin-left:40px;border:1px solid #ccc;display:none;}
#showimg{width:100px;height:100px;background:#fff;cursor:move; position:absolute;border:1px solid #666;opacity:0.5;filter:alpha(opacity=50);display:none;}
</style>
</head>
<body>
<div id="smallimg">
 <img src="/UploadFiles/2021-04-02/m.jpg"> <div id="showimg">&nbsp;</div>
</div>
<div id="bigimg">&nbsp;</div>


<script type="text/javascript">
var $=function(id){return typeof id=="string"?document.getElementById(id):id}
var smallimg = $("smallimg");
var showimg = $("showimg");//滤镜图片
var bigimg = $("bigimg");
var small_url = smallimg.getElementsByTagName("img")[0].getAttribute("src");
var show_half = maxWidth = maxHeight = 0;
smallimg.onmouseover = function(){
 showimg.style.display = "block";
 bigimg.style.display = "inline";
 show_half = showimg.offsetHeight/2;
 maxWidth = smallimg.clientWidth - showimg.offsetWidth;
 maxHeight = smallimg.clientHeight - showimg.offsetHeight;
 //上面两个变量指明showimg允许活动的区域
};
smallimg.onmousemove = function(e){
 var e=window.event?window.event:e;
 var num=bigimg.clientWidth/showimg.clientWidth;
 var Top = e.clientY - smallimg.offsetTop - show_half;
 var Left = e.clientX - smallimg.offsetLeft - show_half;
 //获取当前移动的showimg位置 计算方法是 鼠标坐标 - 最外面容器的坐标 - 盒子的宽(高)的/2
 Top = Top<0?0:Top>maxHeight?maxHeight:Top;
 Left = Left<0?0:Left>maxWidth?maxWidth:Left;
 showimg.style.top = Top + "px";
 showimg.style.left = Left + "px";
 bigimg.style.background = "url("+small_url+") -"+Left*num+"px -"+Top*num+"px no-repeat";
};
smallimg.onmouseout = function(){
 showimg.style.display="none";
 bigimg.style.background ="";
 bigimg.style.display="none"
};
</script>
</body>
</html>

标签:
放大镜,javascript

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?