时间:2021-07-01 10:21:17 帮助过:4人阅读
实现目标:可拖动元素拖动到另外一个元素位置的时候,互相交换位置。
启发来源:最初形式是网上看到的一个拼图小游戏。
运行效果截图如下:

具体代码如下:
代码:
body,ul,li{margin:0;padding:0;}
ul{list-style: none;}
body{font:13px/1.5 Tahoma;}
#box{position:relative;width:435px;height:580px;margin:10px auto;padding: 10px 5px 10px 10px;border: 1px solid #ccc;}
#box li{float:left;width:80px;height:188px;overflow:hidden;background: #ccc;border: 1px solid #999;}
#box li.hig{width:78px;height:186px;overflow:hidden;border:2px dashed blue;}
js代码:
以上就是javascript实现拖动元素交换位置的全部代码,希望对大家的学习有所帮助。