2017-01-09 149 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类型完成所需的功能。