简体   繁体   English

保存相对于父级DIV的jquery拖放位置?

[英]save jquery drag and drop position relative to parent DIV?

I am using php and jquery-ui for saving drag and drop position. 我正在使用php和jquery-ui保存拖放位置。 my problem is its saving top, left position which varies when viewing on a wider screen! 我的问题是它的保存顶部,左侧位置在更宽的屏幕上查看时会有所不同!

how can I save the position realative to parent element? 我该如何将位置实际值保存到父元素?

For this kind of problem i have done something like : 对于这种问题,我做了类似的事情:

I save the position in db using 我使用以下方式将位置保存在db中

parent = $('#theParentElement');
positionX = (parseInt(ui.draggable.css('left'))) / parent.width();
positionY = (parseInt(ui.draggable.css('top'))) / parent.height();

And then when i set the position from db on another client screen. 然后,当我在另一个客户端屏幕上从db设置位置时。

$("#elmtToPosition").css({
        'left':positionX * parent.width(),
        'top':positionY * parent.height()
        }); 

It works for me, try to adapt it. 它对我有用,请尝试使其适应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM