简体   繁体   中英

mousemove handler not called with JQuery .mousemove() or .trigger

when mousemove handler is added with addEventListener(), the handler will never be called with JQuery simulated event by $(xx).mousemove() or $(xx).trigger(e) where e is a jquery event. But the listener can be called when the event is simulated with pure JS dispatchEvent. Anybody can explain? My enviroment is Mac + chrome.

code is here http://jsfiddle.net/eepaul/r8W2h/

<body>
    <ul id="id_ul">
      <li id="a">oooo</li>
      <li id="b">jjjj</li>
    </ul>
    <p id="console"></p>
</body>

js

var liA = $("li#a")[0];
var ul = $("ul")[0];
var p = $("p#console")[0];
ul.addEventListener("mousemove", function(e) {
    $(p).text($(p).text() + "mousemove triggered\n");       
}, false);

var event = $.Event("mousemove", {
    canBubble:true, 
    cancelable: true,
    view:liA.ownerDocument.defaultView,
    detail: 1,
    screenX:0, //The coordinates within the entire page
    screenY: 0,
    clientX: 0, //The coordinates within the viewport
    clientY: 0,
    ctrlKey:false,
    altKey:false,
    shiftKey: false,
    metaKey:false, //I *think* 'meta' is 'Cmd/Apple' on Mac, and 'Windows key' on Win. Not sure, though!
    button: 0, //0 = left, 1 = middle, 2 = right
    relatedTarget:null
 });

//neither of the following 2 ways can trigger the handler   
window.setTimeout(function() {
    $(liA).trigger(event);}, 1000);

window.setTimeout(function() {
    $(liA).mousemove();}, 1000);

Hmm. seems a known issue in jquery. http://bugs.jquery.com/ticket/4314

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM