jQuery div拖拽用法实例
网络编程 2021-07-04 21:04www.168986.cn编程入门
这篇文章主要介绍了jQuery div拖拽用法,以完整实例形式分析了jQuery结合UI插件实现拖拽功能的相关技巧,需要的朋友可以参考下
本文实例讲述了jQuery div拖拽用法。分享给大家供大家参考,具体如下:
这里需要引用好jquery 和 jqueryui两个包:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> <script src="jquery1.8.3.js"></script> <script src="jquery-ui.js"></script> <style> .yuanjian{ float:left; width:180px; height:22px; padding-left:5px; margin-left:5px; margin-:5px; cursor:pointer; border: 1px solid orange; } .fish{ float:left; width:180px; height:22px; padding-left:5px; margin-left:15px; margin-:15px; cursor:pointer; border: 1px solid red; } </style> <script> $(function (){ $('#add_div').droppable({ aept:" .yuanjian ", hoverClass: "droppable-hover", drop: function(event, ui){ if(ele!=''){ if(ele.id.substr(0,13)=="div_yuanjian_"){ var tmpId = "fish_"+ele.id.substr(13,ele.id.length-13); var new_div = "<div class=\"fish\" id=\""+tmpId+"\">"+$('#'+ele.id).html() +" </div>"; $(this).before(new_div); //可以在这里绑定tmpId事件 } } } }); }); var ele = ''; var add_div_num = 0; function add_yuanjian(){ add_div_num++; var div_id = "div_yuanjian_"+add_div_num; var add_div = "<div class=\"yuanjian\" id=\""+div_id+"\">原件"+add_div_num+"</div>"; $('#add_yuanjian_div').before(add_div); $('#'+div_id).mouseover(function(){ $(this).css({background:"#E0E0E0"}); }).mouseout(function(){ $(this).css({background:"#FFFFFF"}); }).draggable({ helper:'clone', opacity:0.5, start:function(event,ui){ ele = event.srcElement || event.target; }}); } </script> </head> <body> <div style="height:400px;width:400px;border:1px solid gray;"> <div style="margin-left:10px;margin-:10px;border:1px solid red;width:100px;height10px;">展示列表 </div> <div id="add_div" style="margin-left:10px;margin-:10px;border:1px solid green;width:350px;height:320px;"> </div> </div> <div style="margin-:10px;height:300px;width:400px; border: 1px solid gray;"> <div style="margin-left:10px;margin-:10px;border:1px solid red;width:250px;height10px;">原件列表 <button onclick="add_yuanjian()">增加原件</button> </div> <div id="add_yuanjian_div"> </div> </div> </body> </html>
更多关于jQuery特效相关内容感兴趣的读者可查看本站专题:《》
希望本文所述对大家jQuery程序设计有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程