如何用JavaScript编写鼠标悬停图片放大缩小功能?

2026-04-01 16:092阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计221个文字,预计阅读时间需要1分钟。

如何用JavaScript编写鼠标悬停图片放大缩小功能?

使用JavaScript实现鼠标拖动图片进行放大缩小功能,代码如下:

如何用JavaScript编写鼠标悬停图片放大缩小功能?

图片拖动放大缩小

使用JS实现鼠标放上图片进行放大离开实现缩小功能,具体代码如下所示:

<!DOCTYPE html> <html> <head> <title></title> </head> <body> <div id= 'div_jpg' style="width: 200px;height: 200px;"> <img src="./128206.jpg" id="img" style="width: 100%;height: 100%;"> </div> <script> var img = document.getElementById('img') var s1,s2 console.log(img) // 图片放大效果 i = 100; img.addEventListener('mouseover',function(){ clearInterval(s1); s1 = setInterval(function(){ i+=0.1; img.style.width = (i)+'%'; img.style.height = (i)+'%'; i = parseFloat(i); if(i>=120) clearInterval(s1); },1); }) img.addEventListener('mouseout',function(){ clearInterval(s2); s2 = setInterval(function(){ i-=0.1; img.style.width = (i)+'%'; img.style.height = (i)+'%'; i = parseFloat(i); if(i<=100) clearInterval(s2); }) }) </script> </body> </html>

分享源码,喜欢的朋友点击查看:

基于jQuery插件Pinchzoom.js实现手指触摸图片放大缩小特效源码

jquery鼠标悬停图片放大滑动显示标题特效

到此这篇关于使用JS实现鼠标放上图片进行放大离开实现缩小功能的文章就介绍到这了,更多相关js图片放大离开缩小内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

本文共计221个文字,预计阅读时间需要1分钟。

如何用JavaScript编写鼠标悬停图片放大缩小功能?

使用JavaScript实现鼠标拖动图片进行放大缩小功能,代码如下:

如何用JavaScript编写鼠标悬停图片放大缩小功能?

图片拖动放大缩小

使用JS实现鼠标放上图片进行放大离开实现缩小功能,具体代码如下所示:

<!DOCTYPE html> <html> <head> <title></title> </head> <body> <div id= 'div_jpg' style="width: 200px;height: 200px;"> <img src="./128206.jpg" id="img" style="width: 100%;height: 100%;"> </div> <script> var img = document.getElementById('img') var s1,s2 console.log(img) // 图片放大效果 i = 100; img.addEventListener('mouseover',function(){ clearInterval(s1); s1 = setInterval(function(){ i+=0.1; img.style.width = (i)+'%'; img.style.height = (i)+'%'; i = parseFloat(i); if(i>=120) clearInterval(s1); },1); }) img.addEventListener('mouseout',function(){ clearInterval(s2); s2 = setInterval(function(){ i-=0.1; img.style.width = (i)+'%'; img.style.height = (i)+'%'; i = parseFloat(i); if(i<=100) clearInterval(s2); }) }) </script> </body> </html>

分享源码,喜欢的朋友点击查看:

基于jQuery插件Pinchzoom.js实现手指触摸图片放大缩小特效源码

jquery鼠标悬停图片放大滑动显示标题特效

到此这篇关于使用JS实现鼠标放上图片进行放大离开实现缩小功能的文章就介绍到这了,更多相关js图片放大离开缩小内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!