设置可拖动div的位置 [英] Set position of draggable div

查看:246
本文介绍了设置可拖动div的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery和JQuery ui做一个小应用程序。

I'm doing a little application using jQuery and JQuery ui.

我已经定义了一个可拖动的div,它运行得很好,但是我想在点击一个按钮时设置div的位置...

I've defined a dragable div, and it works perfectly, but I want to set the position of the div when a click a button...

我在stackOverflow中读到这样做:

I read here in stackOverflow to do this:

element.position().top = topUserDefined;
element.position().left = leftUserDefined;

我在此赋值之前和之后对element.position()。top做了警告。它没有分配,它保留原来的...

I did an alert of element.position().top before and after this assignment and the new value it's not assigned, it keeps the original one...

任何想法???
谢谢!

Any Idea??? Thanks!

推荐答案

.position() 获得该职位。它没有设定位置。它实际上使用 element.offsetLeft element.offsetTop (与 element.offsetParent 位置相比)这些是只读的。

.position() gets the position. It doesn't set the position. It actually uses element.offsetLeft and element.offsetTop (compared to element.offsetParent position) those are read only.

更改内联CSS值以移动元素:

Change inline CSS value to move your element:

element.css({'top': 10, 'left' : 20})

这篇关于设置可拖动div的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆