2014-05-11 8 views
0

모두 즐거운 하루 되세요.휴대 전화에서 터치 이벤트를 처리하기 위해 호버 수정하기

hoverintent.js에 일반적인 문제와 다른 방식으로 mouseOver 이벤트를 처리하는 jquery 플러그인에 몇 가지 문제가 있습니다. 일부 합병증으로 인해이 플러그인의 js 만 수정할 수는 없지만 mouseOver 및 mouseLeave뿐만 아니라 터치 이벤트를 준수해야합니다. 내가 지금까지 한 일을

var handleHover = function(e) { 
// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut 
       var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; 
       while (p && p != this) { try { p = p.parentNode; } catch(e) { p = this; } } 
       if (p == this) { return false; } 

       // copy objects to be passed into t (required for event object to be passed in IE) 
       var ev = jQuery.extend({},e); 
       var ob = this; 

       // cancel hoverIntent timer if it exists 
       if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } 

       // else e.type == "onmouseover" 
       if (e.type == "mouseover") { 
        // set "previous" X and Y position based on initial entry point 
        pX = ev.pageX; pY = ev.pageY; 
        // update "current" X and Y position based on mousemove 
        $(ob).bind("mousemove",track); 
        // start polling interval (self-calling timeout) to compare mouse coordinates over time 
        if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function(){compare(ev,ob);} , cfg.interval);} 

       // else e.type == "onmouseout" 
       } else { 
        // unbind expensive mousemove event 
        $(ob).unbind("mousemove",track); 
        // if hoverIntent state is true, then call the mouseOut function after the specified delay 
        if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function(){delay(ev,ob);} , cfg.timeout);} 
       } 

      } 
     }; 

     // bind the function to the two event listeners 
     return this.mouseover(handleHover).mouseout(handleHover); 

는 휴대폰과 다른 작업 기능을하는 것입니다 :

은 일부 디버깅 후, 나는 수정할 수있는 하나가 될 코드의이 부분을 인식하고 관리해야

  var handleHover = function(e) { 

    isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 


    if(isMobile){ 
      console.log("Ismobile"); 

    }else{ 
      ... Same code as before here ... 
      } 

      // bind the function to the two event listeners 
     return this.mouseover(handleHover).mouseout(handleHover); 

이제 나는 당했다. 나는 마우스 오버 이벤트가 아닌 터치를 처리하기 위해 행동을 "변경"하고 싶습니다. 따라서 휴대 전화에서 요소를 터치해야합니다. 대신 요소 위로 마우스를 가져 가야합니다. 누군가 내게 도움을 줄 수 있을까요? 나는 옳은 길을 가고 있는가? 그것을 생각하는 올바른 방법일까요?

불행히도이 파일과 몇 가지 사항 만 변경할 수 있습니다.

+1

hammer js와 같은 일부 라이브러리가 도움이 될 수 있습니다. http://eightmedia.github.io/hammer .js/또는 단순히 마우스 오버/아웃을 재설정해야하는 경우 클릭 이벤트를 처리하도록 변경하십시오. – keypaul

답변

0

최근에 hoverIntent.js를 변경하면서 몇 가지 문제가 발생하여 내 자신의 플러그인을 작성하게되었습니다. hoverDelay.js (훨씬 간단하고 코드가 적음). 당신이 그것을 사용할 수 있는지 확인하고 자신의 필요에 맞게 수정하십시오. (아마도 모바일 코드에 기여할 수 있습니다 :-)