js做出來的放大镜的效果
来源:互联网 发布:招聘淘宝客服 编辑:程序博客网 时间:2024/05/16 06:07
<!DOCTYPE html>
<html>
<head>
<title>放大镜的效果</title>
<meta charset="utf-8">
<style type="text/css">
*{
padding:0;
margin:0;
}
#class1{
width:200px;
height:300px;
overflow: hidden;
position: relative;
}
#mask{
width: 200px;
height: 300px;
position: absolute;
left: 0;top: 0;
opacity: 0;
filter: alpha(opacity=0);
background-color: red;
}
#mark{
display: none;
width:100px;
height:130px;
background-color: black;
opacity: 0.2;
filter: alpha(opacity=20);
position: absolute; top:0px; left:0px;
display: none;
}
#big_box{
width:400px;
height:600px;
overflow: hidden;
position: absolute; top:20px; left:220px;
display: none;
border:1px solid red;
}
#big{
position: absolute;
left:0px;
top:0px;
}
</style>
<script type="text/javascript">
window.onload=function (){
var mu=document.getElementById("class1");
var markdown=document.getElementById("mark");
var big_tu=document.getElementById("big");
var bi_box=document.getElementById("big_box");
mu.onmouseover=function(){
markdown.style.display="block";
bi_box.style.display="block";
}
mu.onmouseout=function(){
markdown.style.display="none";
bi_box.style.display="none";
}
mu.onmousemove=function(e){
var e=e||event;
var x = e.clientX;//鼠标相对于视口的位置
var y = e.clientY;
var _h=y-markdown.offsetHeight/2;
var _l=x-markdown.offsetWidth/2;
if(_l<0){
_l=0;
}
else if(_l>mu.offsetWidth-markdown.offsetWidth){
_l=mu.offsetWidth-markdown.offsetWidth;
}
if(_h<0){
_h=0;
}
else if(_h>mu.offsetHeight-markdown.offsetHeight){
_h=mu.offsetHeight-markdown.offsetHeight;
}
markdown.style.left=_l+'px';
markdown.style.top=_h+'px';
//这里设置的是其中的那个大图其中的随着其中的可视区域的位置的改变做出的改变
var percentY=_h/(mu.offsetHeight-markdown.offsetHeight);
var percentX=_l/(mu.offsetWidth-markdown.offsetWidth);
big_tu.style.left=-percentX*(big_tu.offsetWidth-bi_box.offsetWidth)+'px';
big_tu.style.top=-percentY*(big_tu.offsetHeight-bi_box.offsetHeight)+'px';
}
}
</script>
</head>
<body>
<div id="class1">
<img src="F://图片/蓝天.jpg" width="200px" height="300px" id="yuan">
<!-- 这里实现的就是其中的遮罩层 -->
<span id="mark"></span>
<div id="mask"></div>
</div>
<div id="big_box">
<img src="F://图片/蓝天.jpg" id="big" width="800px" height="1200px">
</div>
<!-- 这里实现的就是其中的放大图的效果 -->
</body>
</html>
<html>
<head>
<title>放大镜的效果</title>
<meta charset="utf-8">
<style type="text/css">
*{
padding:0;
margin:0;
}
#class1{
width:200px;
height:300px;
overflow: hidden;
position: relative;
}
#mask{
width: 200px;
height: 300px;
position: absolute;
left: 0;top: 0;
opacity: 0;
filter: alpha(opacity=0);
background-color: red;
}
#mark{
display: none;
width:100px;
height:130px;
background-color: black;
opacity: 0.2;
filter: alpha(opacity=20);
position: absolute; top:0px; left:0px;
display: none;
}
#big_box{
width:400px;
height:600px;
overflow: hidden;
position: absolute; top:20px; left:220px;
display: none;
border:1px solid red;
}
#big{
position: absolute;
left:0px;
top:0px;
}
</style>
<script type="text/javascript">
window.onload=function (){
var mu=document.getElementById("class1");
var markdown=document.getElementById("mark");
var big_tu=document.getElementById("big");
var bi_box=document.getElementById("big_box");
mu.onmouseover=function(){
markdown.style.display="block";
bi_box.style.display="block";
}
mu.onmouseout=function(){
markdown.style.display="none";
bi_box.style.display="none";
}
mu.onmousemove=function(e){
var e=e||event;
var x = e.clientX;//鼠标相对于视口的位置
var y = e.clientY;
var _h=y-markdown.offsetHeight/2;
var _l=x-markdown.offsetWidth/2;
if(_l<0){
_l=0;
}
else if(_l>mu.offsetWidth-markdown.offsetWidth){
_l=mu.offsetWidth-markdown.offsetWidth;
}
if(_h<0){
_h=0;
}
else if(_h>mu.offsetHeight-markdown.offsetHeight){
_h=mu.offsetHeight-markdown.offsetHeight;
}
markdown.style.left=_l+'px';
markdown.style.top=_h+'px';
//这里设置的是其中的那个大图其中的随着其中的可视区域的位置的改变做出的改变
var percentY=_h/(mu.offsetHeight-markdown.offsetHeight);
var percentX=_l/(mu.offsetWidth-markdown.offsetWidth);
big_tu.style.left=-percentX*(big_tu.offsetWidth-bi_box.offsetWidth)+'px';
big_tu.style.top=-percentY*(big_tu.offsetHeight-bi_box.offsetHeight)+'px';
}
}
</script>
</head>
<body>
<div id="class1">
<img src="F://图片/蓝天.jpg" width="200px" height="300px" id="yuan">
<!-- 这里实现的就是其中的遮罩层 -->
<span id="mark"></span>
<div id="mask"></div>
</div>
<div id="big_box">
<img src="F://图片/蓝天.jpg" id="big" width="800px" height="1200px">
</div>
<!-- 这里实现的就是其中的放大图的效果 -->
</body>
</html>
阅读全文
0 0
- js做出來的放大镜的效果
- 模拟Flash放大镜的动态JS效果
- js 基础 ---实现放大镜的效果
- 使用js实现放大镜的效果
- 原生JS实现图片的放大镜效果
- H5+css+js的商品放大镜效果
- 简单的js实现放大镜效果
- 有趣的放大镜效果
- 实现放大镜的效果
- 简单的放大镜效果
- View的放大镜效果
- 放大镜效果的制作
- 学习的JS放大镜
- 用js做一个简单的电商放大镜效果
- 利用JS做出来的倒计时的效果
- IE版本的放大镜效果
- jQuery 插件的放大镜效果
- jQuery 插件的放大镜效果
- STM32F0_SYSTICK在STM32CUBEMX中的设置
- java 高级工程师面试
- switch case 语句
- Python3数据类型
- Lombok 安装、入门
- js做出來的放大镜的效果
- Linux字符设备驱动程序开发
- Spark集群无法停止的原因分析和解决
- J-linkage算法学习
- wget\yum配置代理模式
- 了解MySql中的 事务
- 史上最全的前端面试题
- 技术点个人理解
- jupyter notebook 安装多个版本kernel(python2 和python3)