拖放替换javascript jquery [英] Drag Drop Replace javascript jquery

查看:51
本文介绍了拖放替换javascript jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个拖放代码,此刻我有6个可拖放图像,此代码的作用是将图像拖放到另一个图像上时,它们还将交换所有图像交换的位置(例如我想尝试的只是交换2张图片的位置,而剩下的就不用说了.

I am implementing a drag and drop code, what I have at the moment is 6 dragable and dropable images, what this code does is when an image is dragged over another one they swap also all the images swap places as well (like a sort) what Im tryin to do is only swap positions of the 2 images, leaving the rest alone.

看看- http://jsfiddle.net/kommandoss/YuRpU/

任何帮助表示感谢,谢谢

any help appreciated, thanks

推荐答案

它似乎对我有用,当我将图像拖到放在上div中的另一个图像上时,它看起来还不错,它将替换图像中的图像. Upper div,替换的图像将添加到其他图像的末尾.可能我没有完全了解您要寻找的东西...

It seemed to work for me, When I would drag the image over another image I placed in the upper div it seemed fine, It would replace the image in the upper div and the replaced image is added to the end of the other images. Possibly I am not fully understanding what you are looking for...

尽管如此,我确实注意到在此行末尾缺少一个分号:

I did notice a missing semi colon at the end of this line though:

$("#circles").droppable({
    accept: '.circles'
})

$("#circles").droppable({
    accept: '.circles'
});

编辑:如果您希望元素保留在某个位置,则需要为它们应包含的位置定义参数.当前,除非您进行排序或严格将它们相互围绕,否则它们基本上是相互浮动的确定它们要驻留的参数.

If you want the elements to remain in a location you need to define parameters to the location they should be contained in. Currently they are basically floating around each other unless you are sorting or strictly identifying parameters for them to reside in.

您可以在CSS中定义div大小,以将图像包含在一个区域中,这将有助于解决您的问题.

You could define a div size in your CSS to contain the images into an area, this should help solve you issue.

div-name {
   height: 150px; 
   width: 150px;
}

这可将图像限制在一个区域,这样它们就不会在页面中彼此浮动.

This allows the images to stay constrained to an area so they are not simply floating around each other in the page.

这篇关于拖放替换javascript jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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