如何用JS实现画笔的功能,代码是什么
Admin 2022-09-20 群英技术资讯 476 次浏览
实现功能
鼠标点击时可以在画板上画画
如果鼠标双击那么停止
移动进画板颜色改变移除时颜色改变
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> </head> <style> * { margin: 0; padding: 0; box-sizing: border-box; } .drawbox { width: 1100px; height: 600px; background-color: skyblue; position: relative; } </style> <body> <div class="drawbox"></div> <script> /* 1.鼠标点击时可以在画板上画画 如果鼠标双击那么停止 移动进画板颜色改变移除时颜色改变 */ var darwbox = document.querySelector("div"); darwbox.onmouseenter = function() { darwbox.style.backgroundColor = "red"; }; darwbox.onmouseleave = function() { darwbox.style.backgroundColor = "skyblue"; }; var istrue = false; darwbox.onmousedown = function(e) { istrue = true; }; darwbox.onmousemove = function(e) { if (istrue == true) { var x = e.pageX; var y = e.pageY; var circle = document.createElement("div"); circle.style.width = "10px"; circle.style.height = "10px"; circle.style.backgroundColor = "#fff"; circle.style.position = "absolute"; circle.style.left = x - 5 + "px"; circle.style.top = y - 5 + "px"; circle.style.borderRadius = "50%"; darwbox.appendChild(circle); } }; darwbox.onmouseup = function(e) { istrue = false; }; </script> </body> </html>
效果图:
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
node爬虫主要用的是三个插件requestcheeriomysql废话不多说直接上代码constrequest=require("request")constcheerio=require("cheerio")constmysql=require('mysql')varconnection=mysql.createConnection({//
这些年来,ES6 将js的可用性提升到一个新的水平时: 箭头函数、类等等,这些都很棒。箭头函数是最有价值的新功能之一,有很多好文章描述了它的上下文透明性和简短的语法。
这篇文章主要介绍了聊聊vue 中的v-on参数问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
目录vue当前页push当前页无效vue push报错TypeError: Cannot read property ‘push‘ of undefined解决方法vue当前页push当前页无效当在当前页面中push页面跳转当前页,只是push的参数不同时,只能用字符串拼接,parames和query都不会起作用。不知
这篇文章主要介绍了vue+elementUI中表格高亮或字体颜色改变操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008