使用jQuery拖放后如何获取坐标位置? [英] How do I get the coordinate position after using jQuery drag and drop?
本文介绍了使用jQuery拖放后如何获取坐标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jQuery拖放后如何获取坐标位置?我想将坐标保存到数据库中,以便下次访问时,该项目将位于该位置.比如x:520px,y:300px?
How do I get the coordinate position after using jQuery drag and drop? I want to save the coordinate to a database, so that next time I visit, the item will be in that position. For example, x: 520px, y: 300px?
我是 PHP 和 mysql 程序员 :)
I am PHP and mysql programmer :)
有教程吗?
推荐答案
我刚刚做了类似的东西(如果我理解正确的话).
I just made something like that (If I understand you correctly).
我在 jQuery 1.3.2 中使用了函数 position().
I use he function position() include in jQuery 1.3.2.
只是做了一个复制粘贴和一个快速调整......但应该会给你这个想法.
Just did a copy paste and a quick tweak... But should give you the idea.
// Make images draggable.
$(".item").draggable({
// Find original position of dragged image.
start: function(event, ui) {
// Show start dragged position of image.
var Startpos = $(this).position();
$("div#start").text("START:
Left: "+ Startpos.left + "
Top: " + Startpos.top);
},
// Find position where image is dropped.
stop: function(event, ui) {
// Show dropped position.
var Stoppos = $(this).position();
$("div#stop").text("STOP:
Left: "+ Stoppos.left + "
Top: " + Stoppos.top);
}
});
<div id="container">
<img id="productid_1" src="images/pic1.jpg" class="item" alt="" title="" />
<img id="productid_2" src="images/pic2.jpg" class="item" alt="" title="" />
<img id="productid_3" src="images/pic3.jpg" class="item" alt="" title="" />
</div>
<div id="start">Waiting for dragging the image get started...</div>
<div id="stop">Waiting image getting dropped...</div>
这篇关于使用jQuery拖放后如何获取坐标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文