【问题标题】:jquery ui - draggable: onDrag - need to be able to update the css of the draggable...cant :(jquery ui - 可拖动:onDrag - 需要能够更新可拖动的 css...不能 :(
【发布时间】:2014-02-27 17:03:41
【问题描述】:

我正在尝试在您拖动它时更新可拖动对象的位置....但据我所知,在我放入 drag 函数的代码之后,定位是从 jquery ui 更新的(所以它是覆盖我的css)我什至无法改变背景颜色!

我实际上是在拖动 div 并使用 overflow:auto; 在容器中滚动时尝试修复某些问题 .... 如果您想知道我为什么要尝试更新位置。

$(".editable").draggable
({
    grid: [24, 86],
    drag: function(event, ui)
    {
        $('.editable').css({left: '100px'});

        // so im guessing jquery ui is updating the position after this?

    }
});

所以....有什么想法吗?

我基本上需要能够在 jquery ui 更新位置后更新可拖动的位置...但是当您实际上仍在拖动时...我希望这是有道理的:/

在此先感谢,任何意见将不胜感激:)

【问题讨论】:

    标签: jquery jquery-ui jquery-ui-draggable


    【解决方案1】:

    drag 单独无法解决您的问题,您需要使用drag event listener,在创建时您只需定义拖动事件的回调,应用这些更改:

    $(".editable").draggable
    ({
      grid: [24, 86],
      drag: function(event, ui) {} //changed
    });
    
    //event listener
    $( ".editable" ).on( "drag", function( event, ui ) {
      ui.position.left = 100; //check here
    } );
    

    注意我的评论check here,我不太确定您是想将100px 添加到left 还是定义它100px,目前代码将其定义为100px

    【讨论】:

    • 太棒了!非常感谢 G.Mendes! :) ...顺便说一句,以防人们看到这个并且无法让它工作......我不得不将“100px”更改为一个整数(只有 100)......除此之外它工作得很好!
    猜你喜欢
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 2018-04-14
    • 2012-10-29
    • 2018-02-09
    相关资源
    最近更新 更多