帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» 图片放大镜效果
图片放大镜效果
浏览:877次
-
评论:1次
-
发布时间:2018-03-07
Html
Css
Js
* { margin:0; padding:0; border:0; list-style:none; } .b1 { width:400px; height:480px; margin:0 auto; margin-top:100px; border:1px #7fa2a1 solid; position:relative; } .b1 ul { display:flex; } .b1 ul li { margin:auto; } .b1 ul li img { width:50px; height:50px; display:block; } .bian { border:2px red solid; } .b2 img { width:400px; height:400px; margin-bottom:15px; position:relative; } .b2 .sm { width:150px; height:150px; background-color:#000; opacity:0.5; filter:alpha(opacity=50); position:absolute; top:0; left:0; display:none; } .rig { width:400px; height:400px; border:1px #7fa2a1 solid; position:absolute; top:0; left:400px; overflow:hidden; display:none; } .rig img { position:absolute; left:0; top:0; }
var w1 = document.querySelector('.b1 ul'), w2 = document.querySelector('.b2 img'), w3 = document.querySelectorAll('.b1 ul li img'), w4 = document.querySelector('.sm'), w5 = document.querySelector('.b2'), w6 = document.querySelector('.rig img'), w7 = document.querySelector('.rig'); window.anload = (function() { w6.style.width = 400 / 150 * 400 + 'px'; w6.style.height = 400 / 150 * 400 + 'px'; })() w1.addEventListener('mousemove', function(e) { //e.target.tagName //console.log(e.target) //console.log(e) //console.log(e.target) if (e.target.tagName == 'IMG') { w2.src = e.target.src; w6.src = e.target.src; w3.forEach(function(t) { t.className = '' }) e.target.className = 'bian' } }) w5.addEventListener('mousemove', function(e) { w4.style.display = 'block'; w7.style.display = 'block'; var x = e.clientX, y = e.clientY, x1 = w5.getBoundingClientRect().left, y1 = w5.getBoundingClientRect().top, xx = x - x1, yy = y - y1; if (xx <= 75) { xx = 75 } else if (xx >= 325) { xx = 325 } if (yy <= 75) { yy = 75 } else if (yy >= 325) { yy = 325 } w4.style.left = xx - 75 + 'px'; w4.style.top = yy - 75 + 'px'; w6.style.left = -(xx - 75) * (400 / 150) + 'px'; w6.style.top = -(yy - 75) * (400 / 150) + 'px'; }) w5.addEventListener('mouseout', function(e) { w4.style.display = 'none'; w7.style.display = 'none'; })
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
1.11.3
<!doctype html><html><head><meta charset="utf-8"><title>图片放大镜效果-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:淘宝主图放大效果
原生js写的树形下拉菜单效果
canvas声波效果
讨论这个常用代码(1)
回答他人问题或分享心得会奖励牛币
Lv3 码奴
钱***哥
2018年03月07日
前面没有啦!
回复
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
877
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值