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 ...
随机推荐
- 深入理解Linux内核-进程调度
1.什么时候进行进程切换 调度策略目标:1.进程响应尽量快:2.后台作业吞吐量尽量高:3.尽可能避免进程饥饿:4.低优先级和高优先级进程需要尽量调和. 调度策略:决定什么时候选择什么进程运行的规则.基 ...
- 菜鸟译文(一)——Java中的继承和组合
阅读英文的能力对于程序员来说,是很重要的.这几年也一直在学习英文,今天心血来潮,就在网上找了一篇简短的博文翻译一下.水平一般,能力有限,还请各位看官多多指点. 译文: 本文将会举例说明Java中继承和 ...
- shutil 高级文件操作
High-level file operations 高级的文件操作模块,官网:https://docs.python.org/2/library/shutil.html# os模块提供了对目录或者 ...
- mysql_secure_installation
安装完mysql-server 会提示可以运行mysql_secure_installation.运行mysql_secure_installation会执行几个设置: a)为root用户设置密码 ...
- Delphi TWebBrowser编程简述(转帖)
Delphi 3开始有了TWebBrowser构件,不过那时是以ActiveX控件的形式出现的,而且需要自己引入,在其后的4.0和5.0中,它就在封装好shdocvw.dll之后作为Internet构 ...
- 【Mysql】linux连接mysql错误解决方案
1.源码 //connect-mysql.c #include <stdio.h> #include "/usr/include/mysql/mysql.h" int ...
- c++ primer读书笔记之c++11(二)
1 新的STL模板类型,std::initializer_list<T> c++11添加了initializer_list模板类型,用于提供参数是同类型情况的可变长度的参数传递机制,头文件 ...
- Linux下golang开发环境搭建
对于golang开发来说,Windows下可以用vscode或者liteide都不错,但是Linux下的开发也就只有vim了,所以怎么搞笑的利用vim进行golang开发呢? 参考官方推荐的一个插件: ...
- django signal
@receiver(post_save, sender=User) def create_account(sender, instance=None, **kwargs): if instance i ...
- RGB与CMYK以及加色与减色
转载自:http://blog.csdn.net/tohmin/article/details/4761930 黑白色配色与RGB.CMYK 1. 光学三原色与印刷三原色 光学与印刷三原色, 相信大家 ...