js放大镜代码
js原生放大镜
<!DOCTYPE html>
<html>
<head>
<title>放大镜</title>
<meta charset="utf-8">
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
body{
width: 960px;
margin:40px auto;
}
#small{
width: 300px;
height: 200px;
border:1px solid #eee;
border-radius: 4px;
position: relative;
} #small img{
width: %;
height: %;
} div {
float: left;
margin-right: 10px;
} #big{
width: 300px;
height: 200px;
overflow: hidden;
position: relative;
border:1px solid #eee;
border-radius: 4px;
display: none;
} #look_girl{
position: absolute;
left: 0px;
top:0px;
} #move{
width: 100px;
height: 100px;
background:#;
opacity: .;
position: absolute;
display: none;
left: 0px;
top: 0px;
}
</style> </head>
<body>
<div id="small">
<img src="1.png">
<p id="move"></p>
</div>
<div id="big">
<img src="1.png" id="look_girl">
</div>
</body>
<script type="text/javascript">
var move = document.getElementById('move');
var small = document.getElementById('small');
var big = document.getElementById('big');
var look_girl = document.getElementById('look_girl');
small.onmousemove = function(event){
event = event || window.event;
this.style.cursor = 'move';
// 计算move移动块的left值
var move_left = event.clientX - this.offsetLeft - move.offsetWidth/;
// 计算move移动块的top值
var move_top = event.clientY - this.offsetTop - move.offsetHeight/;
// 超出左边界赋值为0
move_left = move_left < ? : move_left;
// 超出右边界赋值为盒子宽度-移动块的宽度
move_left = move_left > this.offsetWidth - move.offsetWidth ? this.offsetWidth - move.offsetWidth : move_left;
// 超出上边界赋值为0
move_top = move_top < ? : move_top;
// 超出下边界赋值为盒子高度-移动块高度
move_top = move_top > this.offsetHeight - move.offsetHeight ? this.offsetHeight - move.offsetHeight : move_top;
// 修改移动块left、top值
move.style.left = move_left + 'px';
move.style.top = move_top + 'px';
/*
计算图片需要移动的坐标 距离左边left 图片宽度 盒子宽度 距离左边left 图片宽度 盒子宽度
big_x/(look_girl.offsetWidth-big.offsetWidth) = move_left/(small.offsetWidth-move.offsetWidth); big_y/(look_girl.offsetHeight-big.offsetHeight) = move_top/(small.offsetHeight-move.offsetHeight); */ var big_x = move_left/(small.offsetWidth-move.offsetWidth) * (look_girl.offsetWidth-big.offsetWidth);
var big_y = move_top/(small.offsetHeight-move.offsetHeight) * (look_girl.offsetHeight-big.offsetHeight);
// 修改图片定位
look_girl.style.left = -big_x + 'px';
look_girl.style.top = -big_y + 'px';
} small.onmouseover = function(){
move.style.display = 'block';
big.style.display = 'block';
} small.onmouseout = function(){
move.style.display = 'none';
big.style.display = 'none';
}
</script>
</html>
js放大镜代码的更多相关文章
- 未封装的js放大镜特效
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>j ...
- js放大镜特效
在平时网上商城购物时,我们能够通过放大镜效果来使我们看图片能够更加的清楚,今天我就来给大家分享一下我学习的放大镜特效 下图是原图的样子 ...
- 网络问卷调查js实现代码
昨天一个同行妹纸写了一个网络问卷调查的效果,但是有bug,于是就来问我该如何解决这个bug.经过我的分析,bug主要还是出在复选框的那部分,经过修改,bug问题解决,现在贴出如下代码,仅供大家参考: ...
- js原生代码实现轮播图案例
一.轮播图是现在网站网页上最常见的效果之一,对于轮播图的功能,要求不同,效果也不同! 我们见过很多通过不同的方式,实现这一效果,但是有很多比较麻烦,而且不容易理解,兼容性也不好. 在这里分享一下,用j ...
- 在Sublime Text 3 中安装SublimeLinter,Node.js进行JS&CSS代码校验
转载自:http://www.wiibil.com/website/sublimelinter-jshint-csslint.html 在Sublime Text中安装SublimeLinter,No ...
- 仿jQuery的siblings效果的js原生代码
仿jQuery的siblings效果的js原生代码 <previousSibling> 属性返回选定节点的上一个同级节点(在相同树层级中的前一个节点). <nextSibling&g ...
- SpringMVC学习系列-后记 结合SpringMVC和Hibernate-validator,根据后台验证规则自动生成前台的js验证代码
在SpringMVC学习系列(6) 之 数据验证中我们已经学习了如何结合Hibernate-validator进行后台的数据合法性验证,但是通常来说后台验证只是第二道保险,为了更好的用户体验会现在前端 ...
- 响应式js幻灯片代码一枚
网站搭建经常会用到js幻灯片轮播,放上几张上档次的美图,为你的爱站增添大气元素.经常看到一些js幻灯片代码,但是感觉不是很美观,有的也不支持自适应缩放,也即是响应式,现在智能手机的普及以及移动浏览器技 ...
- ASP.Net MVC4中封装CSS和js冗余代码(不让其大篇的显示在前台上)
(1)封装CSS和JS代码,使用调用的方式在前台进行调用.是开发看起来简洁和易于管理,可达到重用. 由于asp.netMVC4 框架 ,在封装js和CSS的时候,有如下规范: using Syst ...
随机推荐
- 【Unity】8.3 布局模式(GUILayout)
分类:Unity.C#.VS2015 创建日期:2016-04-27 一.简介 在Unity 5.x中,GUI控件的布局方式有两种. 一种为固定布局,即在绘制控件的时候将位置参数传入,指定控件的精确位 ...
- java 字符串格式化
转:http://blog.sina.com.cn/s/blog_af26e3330101988v.html 1.对整数进行格式化:%[index$][标识][最小宽度]转换方式 我们可以看到,格式化 ...
- (UML总结三)UML与软件project
学习完UML.我们要把它和之前的软件project结合起来.软件project是从总体的角度说了软件开发的步骤.保证了所开发软件的质量.而UML作为一种统一建模语言.是用来设计软件蓝图的可视化建模语言 ...
- 解决failed to get the required adt version from sdk version
在网上看了很多,选择其中的一个解决方法试了下, 还行. AS 2.3之后不能和Eclipse共用一个SDK,给Eclispe重新配置一个SDK路径
- 每日英语:Booming Tech Sector Redraws the Map
China's high-tech companies have made their mark on the nation's economy. Now, with growing cash and ...
- git提交本地代码到新分支
背景: 从branchA分支拉了一份代码,做了一些修改,但是不想提交到branchA分支,想新建一个分支branchB保存代码. 操作方法: 添加本地需要提交代码 git add . 提交本地代码 g ...
- 【转】(四)unity4.6Ugui中文教程文档-------概要-UGUI Visual Components
原创至上,移步请戳:(四)unity4.6Ugui中文教程文档-------概要-UGUI Visual Components 3.Visual Components 有新的组件和游戏对象已添加到uG ...
- Tensorflow网址
https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/1-1-why/ 莫烦视频学习 http://wiki.jikex ...
- KVM虚拟机的xml配置文件
在RHEL6中,用于从磁盘启动的XML文件 这里以dcs01.xml为例: <domain type='kvm'><name>dcs01</name><uui ...
- 【C++程序员学 python】python split and join 分割与合并
感觉这名字有点不对,但不知道用什么好,就将就吧. 坑爹啊,居然要把符号放在前面.