简体   繁体   中英

Touch events are not working on Modal Popup

I am having one simple and complicated problem in touch events on Modal Popup window. In my popup I have displayed one image, for that image I am firing touch event BUT its works some time and NOT work almost all times. Second problem is on that Modal popup only: Swipe events are not at all firing. What might be the problem? Below are warnings I am getting in Logcat: For every touch on Modal popup I am getting this W/webview(5558): Stale touch event ACTION_DOWN received from webcore; ignoring

For swipe on Modal popup I am getting: 11-14 12:42:09.420: W/webview(5558): Miss a drag as we are waiting for WebCore's response for touch down.

Funny thing is only on Modal popup its happening NOT a all screens. Any help would be greatly appreciated

Below javascript code I am using for Modal Popup

var modal = (function() {
var method = {}, $overlay, $modal, $content, $close;

// Center the modal in the viewport
method.center = function() {
    var top, left, position;
    top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
    left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;
    $modal.css({
        top : top + $(window).scrollTop(),
        left : left + $(window).scrollLeft()
    });
};   
// Open the modal
method.open = function(settings) {

    $content.empty().append(settings.content);
    $modal.css({
        width : settings.width || 'auto',
        height : settings.height || 'auto'
    });
    method.center();
    $(window).bind('resize.modal', method.center);
    $modal.show();
    $overlay.show();
};   
// Close the modal
method.close = function() {
    // alert("Called close method");
    $modal.hide();
    $overlay.hide();  
    $content.empty();
    $(window).unbind('resize.modal');
};

// Generate the HTML and add it to the document
// $screen = $()
$overlay = $('<div id="overlay"></div>');
$modal = $('<div id="modal"></div>');
$content = $('<div id="content"></div>');
$close = $('<a id="close" href="#">close</a>');

$modal.hide();
$overlay.hide();
$modal.append($content, $close);
$(document).ready(function() {

    $('body').append($overlay, $modal);
//Here tried with image id, div id and modal BUT No work
document.getElementById("content").addEventListener( 'touchstart',
function(e){ onStart(e); }, false );

    function onStart ( touchEvent ) { 

            var flag = confirm("Are you sure want to defuse it?")
                if (flag == true) {                 
                $('#bombImg').attr('src', 'img/undefused.png');

            } else {   
                $('#bombImg').attr('src', 'img/bomb01.png');
            }
     touchEvent.preventDefault();
            modal.close();

      }
}); 

return method;
 }());   

 // Wait until the DOM has loaded before querying the document
//this method calling from another HTML file
 function showDialog(e) {
disableZoomButtons();
$.get('popUp.html', function(data) {
    modal.open({
        content : data
    });   
});
document.ontouchmove = function(e) {
    return false;
}

modal.open({
    content : "<div id='imgDiv'><img id='bombImg' src='img/bomb01.png'/><br>"
        + "</div>"
});

e.preventDefault();     
}     

Please anybody help me to get resolve this. I am running this app in Android 4.0+

You have to place your onStart() function outside of doc ready :

function onStart ( touchEvent ) { 

        var flag = confirm("Are you sure want to defuse it?")
            if (flag == true) {                 
            $('#bombImg').attr('src', 'img/undefused.png');

        } else {   
            $('#bombImg').attr('src', 'img/bomb01.png');
        }
 touchEvent.preventDefault();
        modal.close();

  }

$(document).ready(function() {

$('body').append($overlay, $modal);
//Here tried with image id, div id and modal BUT No work
document.getElementById("content").addEventListener( 'touchstart',
function(e){ onStart(e); }, false );
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM