jQuery UI & Draggable: Delay Start

jQuery UI Draggable – Delay start

Delay the start of dragging for a number of milliseconds with the delay option; prevent dragging until the cursor is held down and dragged a specifed number of pixels with the distance option.

<!doctype html>
<head>
    <title>jQuery UI Draggable - Delay start</title>
    <link rel='stylesheet' href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css'>
    <script src='//code.jquery.com/jquery-1.9.1.js'></script>
    <script src='//code.jquery.com/ui/1.10.4/jquery-ui.js'></script>
    <link rel='stylesheet' href='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <style>
        #draggable, #draggable2 {
            width: 120px;
            height: 120px;
            padding: 0.5em;
            float: left;
            margin: 0 10px 10px 0;
        }
    </style>
    <script>
        $(function () {
            $('#draggable').draggable({ distance: 40 });
            $('#draggable2').draggable({ delay: 1000 });
            $('.ui-draggable').disableSelection();
        });
    </script>
</head>
<body>

<div id='draggable' class='ui-widget-content'>
    <p>Only if you drag me by 40 pixels, the dragging will start</p>
</div>

<div id='draggable2' class='ui-widget-content'>
    <p>Regardless of the distance, you have to drag and wait for 1000ms before dragging starts</p>
</div>


</body>
</html>
Try The Code

In line 21, the disableSelection() method will prevent the mouse from making any text selection.

Series Navigation<< jQuery UI & Draggable: Visual Feedback
jQuery UI & Draggable: Revert >>