2012-08-02 3 views
1

jQuery를 기능 (자체 작품) :jQuery Mobile에서 페이지 슬라이드를 jQuery 함수와 함께 사용하려면 어떻게해야합니까?

$("#firstpage").live('pageinit', function (evt) { 
    $("#firstpage").bind("swipeleft", function (e) { 
     alert ("you swiped left!"); 
    }); 
}); 

jQuery를 모바일 링크 (또한 자체에서 작동) : 그래서

<a href="#secondpage" data-transition="slide">GO TO PAGE 2</a> 

가 어떻게이 두 가지를 결합 하는가? 감사!

답변

1

당신은 $.mobile.changePage() 방법을 사용하여 그것을 할 수 있습니다.

확인 JQuery와 모바일 문서
http://jquerymobile.com/demos/1.1.1/docs/api/methods.html

$("#firstpage").live('pageinit', function (evt) { 
    $("#firstpage").bind("swipeleft", function (e) { 
     $.mobile.changePage("#secondpage", { transition : 'slide'}); 
    }); 
}); 
+0

감사합니다, 그건 내가 찾던거야. 명백한 이유로 네이티브 앱만큼 반응이 좋지는 않지만 여전히 유용합니다. – orbwhacker

+0

@orbwhacker 응답 성을 원한다면 달성 할 수 있지만'touchstart' /'touchmove' /'touchend'를 사용해야합니다. 체크 아웃 swipejs.com, 그것은 매끄러운 코드입니다. jQuery Mobile 이벤트 인'swipeleft/swiperight'는 반응이 없습니다. – Jasper

2

$.mobile.changePage()은 페이지간에 전환하는 데 내부적으로 사용되는 것입니다. 다음은 그 예이다 : 여기

$(document).delegate("#firstpage", 'pageinit', function (evt) { 
    $(this).bind("swipeleft", function (e) { 
     $.mobile.changePage("#secondpage", { 
      transition : 'slide' 
     }); 
    }); 
}).delegate("#secondpage", 'pageinit', function (evt) { 
    $(this).bind("swiperight", function (e) { 
     $.mobile.changePage("#firstpage", { 
      transition : 'slide', 
      reverse : true 
     }); 
    }); 
});​ 

는 데모입니다 : http://jsfiddle.net/QjUMh/

체크 아웃 문서 $.mobile.changePage과 그것이 가지고있는 모든 옵션을 참조하십시오 http://jquerymobile.com/demos/1.1.1/docs/api/methods.html

관련 문제