1

I implemented a split screen slider using Jquery UI with Touch Punch by dragging an icon - using the jQuery UI "draggable" feature. it works great on the desktop and on the mobile IOS phone. I went along with jQuery 1.12.4., based on some code provided by the author/source.

However, when I use the later jQuery 3.3.1, the dragging fails and I get console errors. The errors I get are:

jquery-ui.min.js:5 
Uncaught TypeError: e(...).find(...).andSelf is not a function
    at e.<computed>.<computed>._getHandle (jquery-ui.min.js:5)
    at e.<computed>.<computed>._getHandle (jquery-ui.min.js:5)
    at e.<computed>.<computed>._mouseCapture (jquery-ui.min.js:5)
    at e.<computed>.<computed>._mouseCapture (jquery-ui.min.js:5)
    at e.<computed>.<computed>._mouseDown (jquery-ui.min.js:5)
    at e.<computed>.<computed>._mouseDown (jquery-ui.min.js:5)
    at HTMLDivElement.<anonymous> (jquery-ui.min.js:5)
    at HTMLDivElement.dispatch (jquery-3.3.1.min.js:2)
    at HTMLDivElement.y.handle (jquery-3.3.1.min.js:2)

Don't quite understand the error messages above. Can anyone provide a fix using the later versions of jQuery (which I am using for many other parts of the site)?

The test code I have worked with below. You can cut/paste into a browser and should find it works as expected - click on the left/right arrows, drag and the split screen moves along with it:

<!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">
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">

    <style>
    #side {
      height: 100%;
      width: 200px;
      position: fixed;
      z-index: -1;
      top: 0px;
      left: 0px;
      background-color: #ffeecc;
    }
    #drag_line{
        width:100px;
        height:100vh;
        position:fixed;
        top: 0px;
        left: 150px;
        background:transparent;
        z-index: 0;
    }
    #drag_handle {
      position: relative;
      top: 40%;
      text-align:center;
      z-index: 1;
      color:#808080;
    }
    #main {
      height: 100vh;
      width: 100%;
      position: fixed;
      top: 0px;
      left: 0px;
      z-index: -1;
      margin-left: 200px;
      padding: 0px;
      background-color: #d9f2d9;
    }
    </style>

</head>
<body>
    <div id="side">SIDE</div>
    <div id="drag_line" style="cursor: pointer;">
        <div id="drag_handle">
            <p style="font-size: 200%;"><i class="fas fa-angle-double-left"></i><i class="fas fa-angle-double-right"></i></p>
            <!--<p id="drag_handle"><i class="fas fa-grip-lines-vertical"></i></p>(alternate image for drag handle symbol)-->
            <p id="xPos">X</p>
        </div>
    </div>
    <div id="main">MAIN</div>   

<script>
$('#drag_line').draggable(
    {axis: "x",//to enable horizontal movement only, not vertical
        drag: function(){            
            var offset = $(this).offset();
            var xPos = Math.round(offset.left);
            //var yPos = offset.top;//not used
            $('#xPos').text(xPos);
            $('#side').width(xPos+50);
            $("#main").css('margin-left',xPos+50);
        }
    });
 </script>
</body>
</html>

The jQuery later version which draggable fails (does not move on click/drag) is:

    <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"" type="text/javascript" charset="utf-8"></script>

Thanks in advance!

hder
  • 67
  • 3
  • 11
  • Welcome to Stack Overflow. Little confused why you are not just using jQuery UI Slider. I have not seen an issue with 3.3.1 and Touch Punch yet Touch Punch may not be up to date. You seem to be using older jQuery UI and Touch Punch versions. – Twisty Jun 09 '19 at 18:00

1 Answers1

0

Don't know the exact reason, but using a JQuery 3.3 along with a later version of JQuery UI 1.12.1 seemed to have solved the problem!

hder
  • 67
  • 3
  • 11