2012-12-20 2 views
0

이 예에서는 swiperight 함수를 먼저 트리거하고 책이 "눌려져 있는지"확인합니다. 바인드를 "눌려진"조건문으로 바꾸는 방법은 무엇입니까? 고맙습니다. 나는 당신이 $("#book").trigger("pressed")를 사용하여 자신을 트리거 사용자 정의 이벤트 같아요 그래서중첩 된 이벤트를 확인하는 방법은 트리거입니까?

$(document).swiperight(function(){ 
     $("#book").bind("pressed", function(event) { // Change this statement to if ($("#book") is "pressed"){..} 
      console.log("pressed"); 
     }); 
}); 
+0

#book은 무엇을하려고? 그리고 '압박'도 재산입니까? – WTK

+0

책이 div이고, 눌러 진 책은 #book입니다. – user782104

+0

'book'이벤트? 이미 해당 이벤트에 바인딩 된 기능이 있는지 확인하려고합니까? – Aesthete

답변

0

$("#book").click(function(event) { 
    var $this = $(this); 
    //emulate toggle button 
    $this.data("pressed", $this.data("pressed") ? '' : 1);  
}); 

$(document).swiperight(function(){ 
    if(!$("#book").data("pressed")) { //If not pressed 
     //your code goes here 
    } 
}); 
+2

Mr. Downvoter : plz 귀찮게 설명해 주겠다. –

+1

나는 똑같은 것을 쓰고 있었다. ('click'이 아니라 'pressed'에, 'pressed'는 커스텀 이벤트이다). 어쨌든 '#book'이 'unpressed'상태 일 때도 추적 할 수있는 컨트롤이 필요합니다. – Polmonite

+0

나는 하나의 downvote가 아니다. 예 @ 폴 모나잇이 아이디어를 얻습니다. 책이 펴지지 않을 때만 무언가를하고 싶습니다. – user782104

-1

는 네이티브 "을 누르면"이벤트가 없습니다. 이 경우, 이벤트가 플래그를 추가 트리거하기 전에 : 검사 할 때마다

$("#book").data("pressed", "true") 
$("#book").trigger("pressed") 

을 다음 :

if ($("#book").data("pressed") === "true") { 
    //already pressed... 
} 
0
$(document).swiperight(function(){ 
     if($("#book").attr("pressed") === "true") { 
      $("#book").bind("pressed", function(event) { 
       $(this).attr("pressed", "true"); 
       console.log("pressed"); 
      }); 
     } 
}); 
관련 문제