JavaScript clientY
clientY屬性屬於事件物件,通常與clientX屬性成對使用。
返回事件被觸發時滑鼠指標在瀏覽器頁面(或者客戶區)的垂直座標。
此屬性非常簡單,關鍵在於理解客戶區是哪一部分,具體參閱瀏覽器客戶區一章節。
語法結構:
[JavaScript] 純文字檢視 複製程式碼event.clientY
瀏覽器支援:
(1).IE瀏覽器支援此屬性。
(2).edge瀏覽器支援此屬性。
(3).火狐瀏覽器支援此屬性。
(4).Opera瀏覽器支援此屬性。
(5).谷歌瀏覽器支援此屬性。
(6).safria瀏覽器支援此屬性。
例項程式碼:
[HTML] 純文字檢視 複製程式碼執行程式碼<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style type="text/css"> #ant{ width:100px; height:100px; background-color:green; } </style> <script> window.onload=function(){ let odiv = document.getElementById("ant"); let ospan = document.getElementById("span"); odiv.onmousemove = function(ev) { let event=ev||event; ospan.innerHTML = "座標值:X:" + event.clientX + " Y:" + event.clientY; } } </script> </head> <body> <div id="ant"></div> <span id="span"></span> </body> </html>
當滑鼠在div元素中移動時,能夠將當前滑鼠在瀏覽器客戶區中的座標寫入span中。
相關文章
- JavaScript高階:JavaScript物件導向,JavaScript內建物件,JavaScript BOM,JavaScript封裝JavaScript物件封裝
- javaScript系列[06]-javaScript和thisJavaScript
- [Javascript] How javascript read the property?JavaScript
- javaScript系列[05]-javaScript和JSONJavaScriptJSON
- “This” is For JavaScriptJavaScript
- This in JavaScriptJavaScript
- JavaScript -"this"JavaScript
- JavaScriptJavaScript
- javascript ??JavaScript
- 44 道 JavaScript 難題(JavaScript Puzzlers!)JavaScript
- [Javascript] Understanding JavaScript Proxies with Symbol.toPrimitiveJavaScriptSymbolMIT
- JavaScript 教程之JavaScript常用框架簡介JavaScript框架
- [Javascript] Perform Set Operations using JavaScript Set MethodsJavaScriptORM
- javascript — == vs ===JavaScript
- JavaScript selectedIndexJavaScriptIndex
- JavaScript deleteCell()JavaScriptdelete
- JavaScript lastElementChildJavaScriptAST
- JavaScript hasAttribute()JavaScript
- JavaScript getAttributeNode()JavaScript
- JavaScript replaceChild()JavaScript
- JavaScript remove()JavaScriptREM
- JavaScript appendChild()JavaScriptAPP
- JavaScript deleteRow()JavaScriptdelete
- JavaScript之thisJavaScript
- JavaScript isFinite()JavaScript
- JavaScript toggle()JavaScript
- JavaScript Boolean()JavaScriptBoolean
- JavaScript escape()JavaScript
- JavaScript parseFloat()JavaScript
- JavaScript unescape()JavaScript
- JavaScript call()JavaScript
- JavaScript bind()JavaScript
- JavaScript previousElementSiblingJavaScript
- JavaScript preventDefault()JavaScript
- JavaScript insertRow()JavaScript
- JavaScript isPrototypeOf()JavaScript
- JavaScript removeChild()JavaScriptREM
- JavaScript nextElementSiblingJavaScript