滑鼠事件 MouseEvent

2022-07-28 01:48:11 字數 874 閱讀 4851

當滑鼠進行某種操作時,就會生成乙個event物件,該物件記錄著滑鼠觸發事件時的所有屬性。

可以通過如下方法在google控制台列印出 mouseevent 物件。

function mousedown(e)

window.onload = function ()

列印出來的 mouseevent  如下:

該物件屬性很多,但最常用的 不過 offsetx、offsety、clientx/clienty、pagex、pagey。各個屬性對應的是什麼呢? 

下面列出一下常用的事件

altkey : 觸發滑鼠事件時是否alt 按鍵被按下,如果按下,則返回true,否則返回 fasle。

button:  事件屬性返回乙個阿拉伯數字 , 0代表 按下 左鍵 ,1 代表按下 滾輪 ,2 代表按下 右鍵。

offsetx、offsety :事件屬性返回觸發事件時 滑鼠相對於事件源元素 的x,y座標,標準事件沒有對應的屬性。

clientx、clienty : 事件屬性返回當事件被觸發時滑鼠指標相對於瀏覽器頁面(或客戶區)的水平座標、垂直座標。

pagex、pagey:事件屬性返回當事件被觸發時滑鼠指標相對於整個頁面左上角的水平座標、垂直座標。

screenx、screeny:事件屬性返回當事件被觸發時滑鼠位置相對於使用者螢幕水水平座標、垂直座標,此時的參照點也就是原點是螢幕的左上角。

好吧,文字敘述總歸是很煩,上個經典的圖,解釋一切 :

(完)

滑鼠事件 MouseEvent

當滑鼠進行某種操作時,就會生成乙個event物件,該物件記錄著滑鼠觸發事件時的所有屬性。可以通過如下方法在google控制台列印出 mouseevent 物件。function mousedown e window.onload function 列印出來的 mouseevent 如下 該物件屬性很...

VB 模擬滑鼠點選 Mouse Event

private declare submouse event lib user32 byval dwflags aslong byval dx as long byval dy as long byval cbuttons aslong byval dwextrainfo aslong const ...

滑鼠事件 跟隨滑鼠移動

案例分析 1.滑鼠不斷移動,使用滑鼠移動事件 mousemove 2.在頁面中不斷移動,給document註冊事件 3.要移動距離,而且不佔位置,我們使用絕對定位 效果 跟隨滑鼠的天使 title 6 style 7img 11style 12head 13 body 14 img src pic....