js放大镜效果例子
来源:互联网 发布:党员 信仰 知乎 编辑:程序博客网 时间:2024/05/16 05:09
只需要更改图片地址就可以实现放大镜效果
<!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>
</head>
<body>
<style type="text/css">
#div1 {
width: 304px;
height: 222px;
position: relative;
margin: 30px auto 0px;
}
#div1 img {
width: 304px;
height: 222px;
}
#div1 span {
width: 100px;
height: 100px;
background: red;
left: 0px;
top: 0px;
position: absolute;
display: none;
filter:alpha(opacity:20);
opacity: 0.2;
}
.show {
width: 100%;
height: 100%;
background: red;
position: absolute;
z-index: 10px;
filter:alpha(opacity:10);
opacity: 0.1;
left: 0px;
top: 0px;
}
#div2 {
width: 304px;
height: 222px;
position: relative;
display: none;
overflow: hidden;
margin: 0px auto 0px;
}
#img1 {
position: absolute;
}
</style>
<script type="text/javascript">
window.onload=function ()
{
var oDiv=document.getElementById('div1');
var oShow=oDiv.getElementsByTagName('div')[0];
var oSpan=oDiv.getElementsByTagName('span')[0];
var oImg=document.getElementById('img1');
oShow.onmouseover=function()
{
oSpan.style.display='block';
oImg.parentNode.style.display='block';
};
oShow.onmouseout=function()
{
oSpan.style.display='none';
oImg.parentNode.style.display='none';
};
oShow.onmousemove=function(ev)
{
var oEvent=ev||event;
var x=oEvent.clientX-oDiv.offsetLeft-oSpan.offsetWidth/2;
var y=oEvent.clientY-oDiv.offsetTop-oSpan.offsetHeight/2;
if(x<0)
{
x=0;
}
else if(x>oShow.offsetWidth-oSpan.offsetWidth)
{
x=oShow.offsetWidth-oSpan.offsetWidth;
}
if(y<0)
{
y=0;
}
else if(y>oShow.offsetHeight-oSpan.offsetHeight)
{
y=oShow.offsetHeight-oSpan.offsetHeight
}
oSpan.style.left=x+'px';
oSpan.style.top=y+'px';
var percentX=x/(oShow.offsetWidth-oSpan.offsetWidth);
var percentY=y/(oShow.offsetHeight-oSpan.offsetHeight);
var oImgparent=oImg.parentNode;
oImg.style.left=-percentX*(oImg.offsetWidth-oImgparent.offsetWidth)+'px';
oImg.style.top=-percentY*(oImg.offsetHeight-oImgparent.offsetHeight)+'px';
};
};
</script>
<div id="div1">
<img src="11_2_2.jpg" />
<span></span>
<div class="show"></div>
</div>
<div id="div2">
<img id="img1" src="11_2_2.jpg" />
</div>
</body>
</html>
0 0
- js放大镜效果例子
- js放大镜,淘宝效果
- JS放大镜效果
- js放大镜效果
- js放大镜效果
- jS放大镜效果
- JS:放大镜效果
- JS实现放大镜效果
- js实现放大镜效果
- js实现放大镜效果
- js放大镜效果
- 淘宝放大镜例子(js)
- 原生js - 图片放大镜效果
- js图片局部放大镜效果
- js放大镜效果,超强注释
- js实现图片放大镜效果
- js制作淘宝放大镜效果
- js实现淘宝放大镜效果
- 自定义照相机
- 什么是韵律词、韵律短语、语调短语?
- ORACLE索引介绍和使用
- CentOS Apache服务器安装
- First day
- js放大镜效果例子
- HTML5学习之FileReader接口
- LSI MegaRAID(IBM服务器web页面) 8708E SAS RAID卡如何使用手动方式创建RAID5+热备盘
- Kettle连接MySQL数据库出现问题,连接不上
- dyld: Library not loaded: @rpath/*.framework/*
- 使用XFire构建WebService客户端
- iOS-UIKit( UIBezierPath.h - -解读)
- 生成全局唯一标识符,类似 09315E33-480F-8635-E780-7A8E61FB49AA
- error C2039: “SetDefaultDllDirectories”: 不是“`global namespace'”的成员