Target.addEventListener( ) 監聽物件 Target.addEventListener(event,function,Capture) Target : 監聽物件,表示觸發事件的元素 Document、Window、id..... event : mousedown、mouseenter、mouseleave、mousemove、 監聽事件 mouseout、mouseover、mouseup、mousewheel 、 click、dblclick keydown、keypress、keyup blur、focus、abort、beforeinput、 compositionstart、compositionupdate、compositionend、 error、focusin、focusout、input、load、resize、 scroll、select、unload、wheelTarget.removeEventListener() 刪除監聽 removeEventListener()方法用於刪除與addEventListener(), 方法關聯的事件處理程序。
Target.addEventListener(event ,function(e){} ,false) event. MouseEvent 監聽事件 : mouseenter 移動進入 父元素 的時候會觸發。 mouseleave 移動離開 父元素 的時候會觸發。 mouseover 移動進入到元素上時就會觸發。 mouseout 移動離開到元素上時就會觸發。 mouseup 放開滑鼠按鍵時發生。 mousedown 按一下滑鼠按鍵時發生, 屬性返回, e.detail 0:無按鍵 1:按鍵 e.button 0:左鍵 1:中間鍵 2:加鍵 mousemove 鼠標移動位置, 屬性返回, e.pageX 與文檔左側邊緣的距離(單位像素) e.pageY 與文檔上側邊緣的距離(單位像素) mousewheel 滾輪事件。
<div id="mainID"> click me 1 click me 2 click me 3 click me 4 click me 5</div>
mainID.addEventListener('click', function(e){ e.target.style.color=rgb ; }) e.target : mainID 內的物件。
addEventListener click move 點擊 移動 事件window.addEventListener('mouseup', function(e){ Dw=0 })DIV.addEventListener('mousedown',function(e){ Dw=1 })window.addEventListener('mousemove', function(e){ if(Dw==1 ) { DIV.style.top =e.pageY-30+"px" ; DIV.style.left=e.pageX-30+"px" ;} })
沒有留言:
張貼留言