簡體   English   中英

JQuery UI Draggable與更新的JQuery 3.3失敗(使用JQuery UI Touch Punch)

[英]JQuery UI Draggable Fails with newer JQuery 3.3 (using JQuery UI Touch Punch)

我使用Jquery UI和Touch Punch實現了一個分屏滑塊,通過拖動圖標 - 使用jQuery UI“draggable”功能。 它在桌面和移動IOS手機上運行良好。 我根據作者/來源提供的一些代碼,使用了jQuery 1.12.4。

但是,當我使用后面的jQuery 3.3.1時,拖動失敗並且我得到控制台錯誤。 我得到的錯誤是:

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)

不太明白上面的錯誤消息。 任何人都可以使用更高版本的jQuery(我用於網站的許多其他部分)提供修復?

我在下面使用的測試代碼。 您可以剪切/粘貼到瀏覽器中,並且應該找到它按預期工作 - 單擊左/右箭頭,拖動,分割屏幕隨之移動:

<!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>

可拖動失敗的jQuery更新版本(不會單擊/拖動):

    <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>

提前致謝!

不知道確切的原因,但使用JQuery 3.3以及更高版本的JQuery UI 1.12.1似乎已經解決了這個問題!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM