메신저 jquery/javascript에 새로 추가되었습니다. 그래서 여기에, 나는이 js 코드를 swipedown 및 swipeup에 대해 찾았습니다. 그러나 그것을 사용하거나 호출하는 방법을 모른다. javascript/jquery에서이 함수를 사용/호출하는 방법?
는 JS 번호 :$('#swipedown').live('swipedown', function(event, data){
alert('swipes')
});
:
(function() {
// initializes touch and scroll events
var supportTouch = $.support.touch,
scrollEvent = "touchmove scroll",
touchStartEvent = supportTouch ? "touchstart" : "mousedown",
touchStopEvent = supportTouch ? "touchend" : "mouseup",
touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
// handles swipeup and swipedown
$.event.special.swipeupdown = {
setup: function() {
var thisObject = this;
var $this = $(thisObject);
$this.bind(touchStartEvent, function(event) {
var data = event.originalEvent.touches ?
event.originalEvent.touches[ 0 ] :
event,
start = {
time: (new Date).getTime(),
coords: [ data.pageX, data.pageY ],
origin: $(event.target)
},
stop;
function moveHandler(event) {
if (!start) {
return;
}
var data = event.originalEvent.touches ?
event.originalEvent.touches[ 0 ] :
event;
stop = {
time: (new Date).getTime(),
coords: [ data.pageX, data.pageY ]
};
// prevent scrolling
if (Math.abs(start.coords[1] - stop.coords[1]) > 10) {
event.preventDefault();
}
}
$this
.bind(touchMoveEvent, moveHandler)
.one(touchStopEvent, function(event) {
$this.unbind(touchMoveEvent, moveHandler);
if (start && stop) {
if (stop.time - start.time < 1000 &&
Math.abs(start.coords[1] - stop.coords[1]) > 30 &&
Math.abs(start.coords[0] - stop.coords[0]) < 75) {
start.origin
.trigger("swipeupdown")
.trigger(start.coords[1] > stop.coords[1] ? "swipeup" : "swipedown");
}
}
start = stop = undefined;
});
});
}
};
//Adds the events to the jQuery events special collection
$.each({
swipedown: "swipeupdown",
swipeup: "swipeupdown"
}, function(event, sourceEvent){
$.event.special[event] = {
setup: function(){
$(this).bind(sourceEvent, $.noop);
}
};
});
})();
이 I 위의 코드
<a href="<?php echo base_url();?>home/drop_down" id="swipedown"></a>
를 사용하여 트리거 할 앵커 원소
이 같은 함수를 호출하려고 그러나 그것은 나에게 경고를 촉구하지 않았다. >. <. 도움이 될 것입니다.
은 당신이 플러그를 찾을 때마다 문서가 아닌가? – Scott
코드가 자동으로 실행됩니다. 즉, 스크립트가로드되는 즉시이 함수가 실행됩니다. 그리고 그것은 jQuery 이벤트 컬렉션에 swipeupdown 이벤트를 추가합니다. – Zlatko
@scott 어떤 문서도 찾지 못했고 링크는 다음과 같습니다. http://snipt.net/blackdynamo/swipe-up-and-down-support-for-jquery-mobile –