您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

canvas实现图片根据滑块放大缩小效果

2025/5/10 4:00:11发布20次查看
本文主要介绍了canvas实现图片根据滑块放大缩小效果的实例,具有很好的参考价值,下面跟着小编一起来看下吧
效果图:
图(1) 原始图
图(2) 缩小后
图(3) 放大后
代码如下:
<!doctype html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> #canvas1{ box-shadow: 3px 3px 10px black; } </style> </head> <body> <canvas id="canvas1" width="500" height="500"></canvas> <input type="range" name="slider" id="silder" value="0.5" max="1" min="0" step="0.01"/> </body> <script type="text/javascript"> var canvas = document.getelementbyid("canvas1"); var context = canvas.getcontext("2d"); var slider = document.getelementbyid("silder"); var scale = slider.value; creatimg(scale); slider.onmousedown = function() { slider.onmousemove = function () { scale = slider.value; creatimg(scale); } } function creatimg (scale) { var myimg = new image(); myimg.src = "https://gss0.baidu.com/-vo3dsag_xi4khgko9wtanf6hhy/zhidao/pic/item/902397dda144ad34ac75c376d7a20cf430ad857d.jpg" var imgh = canvas.height * scale; var imgw = canvas.width * scale; var x = canvas.width / 2 - imgw / 2; var y = canvas.height / 2 - imgh / 2 myimg.onload = function () { context.clearrect(0 , 0 , canvas.width , canvas.height); context.drawimage(myimg , x , y ,imgw , imgh) } } </script> </html>
更多canvas实现图片根据滑块放大缩小效果。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product