最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Swipe, swipeleft, swiperight events do not trigger on image - Stack Overflow

programmeradmin3浏览0评论

I want use jQuery mobile's swiperight event in bination with an image, which doesn't seem to function.

HTML:

<div id="one"><img src=".png"/></div>
<div id="two">works</div>

JS:

$("#one").on("swiperight", function() {
    alert("does not work");
});
$("#two").on("swiperight", function() {
    alert("works");
});

JSFiddle

I want use jQuery mobile's swiperight event in bination with an image, which doesn't seem to function.

HTML:

<div id="one"><img src="http://jquerymobile./wp-content/uploads/2012/09/jquery-mobile-logo-03.png"/></div>
<div id="two">works</div>

JS:

$("#one").on("swiperight", function() {
    alert("does not work");
});
$("#two").on("swiperight", function() {
    alert("works");
});

JSFiddle

Share Improve this question edited Mar 25, 2013 at 17:15 Gajotres 57.3k16 gold badges105 silver badges131 bronze badges asked Mar 25, 2013 at 8:42 jgillichjgillich 76.6k7 gold badges60 silver badges88 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

I'm quite sure only desktop browser have this issue as mobile browsers usually don't drag images on swipe.

The solution suggested here prevents dragging your image in all browsers:

$('img').on('dragstart', function(event) {
    event.preventDefault();
});

So here is your new working fiddle: http://jsfiddle/4CbEQ/1/

You need to prevent image dragging, here's a working example: http://jsfiddle/Gajotres/SgUZK/

$(document).on('pagebeforeshow', '#index', function(){   
    $('img').on('dragstart', function(event) { event.preventDefault(); });

    $("#one").on("swiperight", function() {
        alert("does not work");
    });
    $("#two").on("swiperight", function() {
        alert("works");
    });
});
发布评论

评论列表(0)

  1. 暂无评论