0

I have created drag and drop functionality like matching the things , its working fine in the browser. But when i checked same thing in the touch devices like iPad its not working and even the drag functionality is not triggered. Help me in resolving this issue.

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="dragg-elem">
    <div id="one">1</div>
    <div id="two">2</div>
    <div id="three">3</div>
    <div id="four">4</div>
    <div id="five">5</div>
</div>
<div class="dragged-result">
    <div id="one">One</div>
    <div id="two">Two</div>
    <div id="three">three</div>
    <div id="four">Four</div>
    <div id="five">Five</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
</html>

Css code:

.dragg-elem div ,
.dragged-result div{
   width: 100px;
   height: 100px;
   border: 2px solid #ccc;
   display: inline-flex;
   justify-content:center;
   align-items:center;
 }
.dragged-result {
  margin-top: 20px;
 }

Js code:

$(document).ready(function(){
var dragElemId;
$( ".dragg-elem > div" ).draggable({
drag: function(event,ui){
    dragElemId = $(this).attr('id');
    console.log(dragElemId);
    },
    revert: true, 
})
$( ".dragged-result div" ).droppable({      
    accept: '.dragg-elem > div',
    drop: function(e,ui){   
        droppedElem = $(this).attr('id');
        console.log(droppedElem);
        if(droppedElem === dragElemId){
        ui.draggable.css('color', 'green');
        ui.draggable.draggable('option', 'revert', false);
        }
    }
})
});
John_ny
  • 767
  • 12
  • 33
  • https://stackoverflow.com/questions/13940421/how-to-get-jqueryui-drag-drop-working-with-touch-devices – R3tep Jan 02 '19 at 12:06
  • Possible duplicate of [How to get jQueryUI drag\drop working with touch devices](https://stackoverflow.com/questions/13940421/how-to-get-jqueryui-drag-drop-working-with-touch-devices) – Liam Jan 02 '19 at 12:07
  • 1
    jquery UI is very 2010. If you want a proper UI solution (especially one that is responsive and works on multiple devices) you really should be thinking about using a more up to date framework like Bootstrap. Jquery UI hasn't [received a major update since 2016](https://jqueryui.com/changelog/1.12.1/) – Liam Jan 02 '19 at 12:09
  • Have you tried using the latest version of jQuery UI? I see you have v1.8.1. May also consider using TouchPunch too. – Twisty Jan 02 '19 at 16:50

1 Answers1

0

For this version of jquery ui library, use the following touch punch jquery ui

https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js

I hope this will fix the issue

Anitha C
  • 56
  • 6