2017-01-09 155 views
2

我遇到了使用jQuery訪問事件的事件座標的問題。我的代碼如下。每當我更改音量滑塊時,它將返回undefined而不是光標位置。jQuery e.clientX返回undefined

$(document).ready(function(){ 
     // for new browsers 
    $("input#volume").bind('input', function(e){ 
     if (is_playing()) { 
      now_playing.volume = parseFloat((this.value/100)); 
      // set the tooltp for the current volume 
      var vol_tooltip = Math.floor((this.value/100)*100); 
      // $(".seek_timer").remove(); 
      console.log(e.clientX); 
      // $(".slider-wrap").append("<span class='seek_timer'>"+vol_tooltip+"</span>"); 
      // $(".seek_timer").css("left",e.clientX-15+"px"); 
     } 
    }); 
}); 

爲什麼e.clientX未定義?

+0

據我所知輸入不是鼠標事件,因此它沒有鼠標位置。 –

回答

0

你綁定到input事件,其中不包括座標 - 座標只出現在其使用MouseEvent interface事件,如clickmousedownmouseup事件。如果您希望能夠通過clientXclientY屬性捕獲客戶端位置座標,則需要重新設計代碼,以便使用其中一種MouseEvent類型完成所需的功能。