JavaScript實(shí)現(xiàn)鼠標(biāo)移動(dòng)事件畫(huà)筆
JavaScript實(shí)現(xiàn)鼠標(biāo)移動(dòng)事件畫(huà)筆小游戲,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)功能
鼠標(biāo)點(diǎn)擊時(shí)可以在畫(huà)板上畫(huà)畫(huà)
如果鼠標(biāo)雙擊那么停止
移動(dòng)進(jìn)畫(huà)板顏色改變移除時(shí)顏色改變
<!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.鼠標(biāo)點(diǎn)擊時(shí)可以在畫(huà)板上畫(huà)畫(huà) ? ? ? ? 如果鼠標(biāo)雙擊那么停止 ? ? ? ? 移動(dòng)進(jìn)畫(huà)板顏色改變移除時(shí)顏色改變 ? ? ? ? */ ? ? ? 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>
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS/jQuery實(shí)現(xiàn)默認(rèn)顯示部分文字點(diǎn)擊按鈕顯示全部?jī)?nèi)容
默認(rèn)顯示部分文字,點(diǎn)擊按鈕顯示全部,類(lèi)似這樣的功能在一些特殊的地方會(huì)見(jiàn)到吧,下面與大家分享下JS、jQuery如何實(shí)現(xiàn),感興趣的朋友可以參考下哈,希望對(duì)你有所幫助2013-05-05在標(biāo)題欄顯示新消息提示,很多公司項(xiàng)目中用到這個(gè)方法
在標(biāo)題欄顯示新消息提示,很多公司項(xiàng)目中用到這個(gè)方法,需要的朋友可以參考下。2011-11-11Javascript new關(guān)鍵字的玄機(jī) 以及其它
本人是Javascript菜鳥(niǎo),下面是前幾天學(xué)習(xí)Javascript的旅程心得,希望對(duì)和我一樣的入門(mén)者有點(diǎn)用,也希望高手批評(píng)指正。2010-08-08js仿QQ中對(duì)聯(lián)系人向左滑動(dòng)、滑出刪除按鈕的操作
這篇文章主要介紹了js仿QQ中對(duì)聯(lián)系人向左滑動(dòng)、滑出刪除按鈕的操作,即編寫(xiě)一個(gè)js向左滑動(dòng)刪除 交互特效的插件,感興趣的小伙伴們可以參考一下2016-04-04JavaScript實(shí)現(xiàn)動(dòng)態(tài)時(shí)鐘效果
這篇文章主要介紹了JavaScript實(shí)現(xiàn)動(dòng)態(tài)時(shí)鐘效果,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下,希望對(duì)你的學(xué)習(xí)有所幫助2022-06-06JavaScript對(duì)象數(shù)組如何按指定屬性和排序方向進(jìn)行排序
這篇文章主要介紹了JavaScript對(duì)象數(shù)組如何按指定屬性和排序方向進(jìn)行排序的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06PHP自動(dòng)加載autoload和命名空間的應(yīng)用小結(jié)
PHP的自動(dòng)加載就是我們加載實(shí)例化類(lèi)的時(shí)候,不需要手動(dòng)去寫(xiě)require來(lái)導(dǎo)入這個(gè)class.php文件,程序自動(dòng)幫我們加載導(dǎo)入進(jìn)來(lái)這.篇文章主要介紹了PHP自動(dòng)加載autoload和命名空的應(yīng)用,需要的朋友可以參考下2017-12-12