Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui jquery ui可拖动的停止加速_Jquery Ui_Jquery Ui Draggable - Fatal编程技术网

Jquery ui jquery ui可拖动的停止加速

Jquery ui jquery ui可拖动的停止加速,jquery-ui,jquery-ui-draggable,Jquery Ui,Jquery Ui Draggable,我正在使用jQueryUIDragTable来拖动一个div。在阻力停止后,平滑缓解阻力的最佳方法是什么? 假设阻力突然停止 谢谢您使用easing实现draggables可能对您有用。这是我对上一个线程的回答中的一个简化解决方案,它更具体: HTML: Javascript: $(function() { $("#draggable").draggable({ helper: function(){ // Create an invisible

我正在使用jQueryUIDragTable来拖动一个div。在阻力停止后,平滑缓解阻力的最佳方法是什么? 假设阻力突然停止


谢谢您

使用easing实现draggables可能对您有用。这是我对上一个线程的回答中的一个简化解决方案,它更具体:

HTML:

Javascript:

$(function() {
    $("#draggable").draggable({
        helper: function(){
            // Create an invisible div as the helper. It will move and
            // follow the cursor as usual.
            return $('<div></div>').css('opacity',0);
        },
        drag: function(event, ui){
            // During dragging, animate the original object to
            // follow the invisible helper with custom easing.
            var p = ui.helper.position();
            $(this).stop().animate({
                top: p.top,
                left: p.left
            },1000,'easeOutCirc');
        }
    });
});
$(函数(){
$(“#可拖动”)。可拖动({
助手:函数(){
//创建一个不可见的div作为辅助对象。它将移动并
//像往常一样跟随光标。
返回$('').css('opacity',0);
},
拖动:函数(事件、ui){
//在拖动过程中,将原始对象设置为动画
//跟随不可见的辅助对象进行自定义调整。
var p=ui.helper.position();
$(this).stop().animate({
top:p.top,
左:p.left
},1000,'easeOutCirc');
}
});
});

JSFIDLE demo:

位置:相对位置非常重要,花了一段时间才明白这一点!伟大的解决方案-简单、易懂且有效。
#draggable {
    position: relative;
    width: 100px;
    height: 100px;
    background-color: whitesmoke;
    border: 2px solid silver;
}
$(function() {
    $("#draggable").draggable({
        helper: function(){
            // Create an invisible div as the helper. It will move and
            // follow the cursor as usual.
            return $('<div></div>').css('opacity',0);
        },
        drag: function(event, ui){
            // During dragging, animate the original object to
            // follow the invisible helper with custom easing.
            var p = ui.helper.position();
            $(this).stop().animate({
                top: p.top,
                left: p.left
            },1000,'easeOutCirc');
        }
    });
});