Html
<html>
<!-- heading -->
<head>
<meta charset="utf-8">
<title>Example</title>
</head>
<!-- page -->
<body>
<!-- connect libraries jQuery and jQuery UI -->
<script src="https://dir.by/example_lib/jquery/jquery-3.3.1.min.js"></script>
<script src="https://dir.by/example_lib/jquery_ui/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<!-- HTML Elements -->
<div id="myElement1" style='height:100px; width:100px; float:left; background-color:#e9e9e9; cursor:hand; margin-right:20px;'>
<p>Click on me and drag me with your mouse</p>
</div>
<div id="myElement2" style='height:250px; width:250px; float:left; background-color:#d0d0d0;'>
<p>Quit here</p>
</div>
<!-- JavaScript -->
<script>
// the page has opened
$( function()
{
// call the method draggable so that the item can be dragged myElement1
$("#myElement1").draggable();
// Call droppable to an element myElement1 could be thrown into an item myElement2
$("#myElement2").droppable(
{
// handler (what we will do when throwing myElement1)
drop: function(event, ui)
{
// change color
$(this).css("background-color", "#f0f0a0");
// change the text
$(this).find("p").html("Item thrown");
}
});
});
</script>
</body>
</html>
Explanation
One line is added to the code, this is the connection of the library
jQuery UI Touch Punch ... to drag and drop on tablet, phone.
Html
<script src="https://dir.by/example_lib/touch-punch/jquery.ui.touch-punch.js"></script>
All example code to drag and drop on tablet, phone
In the code, the added line is highlighted
Blue.
Html
<html>
<!-- heading -->
<head>
<meta charset="utf-8">
<title>Example</title>
</head>
<!-- page -->
<body>
<!-- connect libraries jQuery and jQuery UI -->
<script src="https://dir.by/example_lib/jquery/jquery-3.3.1.min.js"></script>
<script src="https://dir.by/example_lib/jquery_ui/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<!-- drag-and-drop library for tablet, phone -->
<script src="https://dir.by/example_lib/touch-punch/jquery.ui.touch-punch.js"></script>
<!-- HTML Elements -->
<div id="myElement1" style='height:100px; width:100px; float:left; background-color:#e9e9e9; cursor:hand; margin-right:20px;'>
<p>Click on me and drag me with your mouse</p>
</div>
<div id="myElement2" style='height:250px; width:250px; float:left; background-color:#d0d0d0;'>
<p>Quit here</p>
</div>
<!-- JavaScript -->
<script>
// the page has opened
$( function()
{
// call the method draggable to an element myElement1 could be dragged
$("#myElement1").draggable();
// Call droppable to an element myElement1 could be thrown into an item myElement2
$("#myElement2").droppable(
{
// handler (what we will do when throwing myElement1)
drop: function(event, ui)
{
// change color
$(this).css("background-color", "#f0f0a0");
// change the text
$(this).find("p").html("Item thrown");
}
});
});
</script>
</body>
</html>