0

There are countless jquery plugin for this. But I found none that work in Edge, Chrome, Firefox and Safari, mouse and touch. Do you know a proper stable solution? It doesn't have to be jquery based. Can be also native JS.


Thanks @Alexis, with your hint I figured out a solution that seems to work. Here the core functionality:

var drag = false;

$('#map').on( "mousedown touchstart", function(e){
    drag = true;
    console.log('start');
});
$('#map').on( "touchmove", function(e){
  if (e.targetTouches.length == 1 && drag == true) {
    var touch = e.targetTouches[0];
    console.log(touch);
  }
});
$('#map').on( "mousemove", function(e){
  if (drag == true) {
    console.log(e.pageX);
  }
});
$('#map').on( "mouseup touchend", function(e){
  drag = false;
  console.log('end');
});
user3168511
  • 254
  • 1
  • 15

1 Answers1

1

jQuery UI drag n drop is cross-browser as far as i know :

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Draggable - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  #draggable { width: 150px; height: 150px; padding: 0.5em; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#draggable" ).draggable();
  } );
  </script>
</head>
<body>

<div id="draggable" class="ui-widget-content">
  <p>Drag me around</p>
</div>


</body>
</html>

js fiddle :

https://jsfiddle.net/riazxrazor/swepy32t/

Riaz Laskar
  • 1,317
  • 9
  • 17