关于常见的左右赋权限的移动样式
来源:互联网 发布:php socket了解 编辑:程序博客网 时间:2024/06/16 19:07
效果如图:
代码如下:
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>拖拽演示</title> <script type="text/javascript" src="js/jquery-2.1.1.min.js" ></script> <style type="text/css"> *{ margin: 0; padding: 0; } .box{ width: 960px; height: auto; /*border: 5px solid #ddd;*/ margin: 30px auto; } .box1{ width: 400px; min-height: 190px; float: left; border: 5px solid #360; } .box2{ width: 400px; min-height: 190px; float: right; border: 5px solid #630; } li{ list-style: none; width: 100%; height: 30px; line-height: 30px; text-indent: 30px; border-bottom: 1px solid #fff; background: #ddd; color: #f00; font:800 14px/30px "微软雅黑"; cursor: pointer; } .box3{ width: 140px; height: 60px; float: left; } .box3 li{ background: #999; font-weight: 800; width: 100px; height: 30px; margin: 50px auto; color: #fff; border-radius: 5px; } .active{ color: #fff; background: #f00; } </style> </head> <body> <div class="box"> <div class="box1"> <ul> <li>11111111</li> <li>22222222</li> <li>33333333</li> <li>44444444</li> </ul> </div> <div class="box3"> <li from=".box1" to=".box2">====></li> <li from=".box2" to=".box1"><====</li> </div> <div class="box2"> <ul> <li>5555555</li> <li>6666666</li> <li>7777777</li> </ul> </div> </div> </body> <script type="text/javascript"> (function($){ $(function(){ /*给每个元素添加draggable = true属性*/ $(".box1 ul li").each(function(index,element){ $(this).attr({"draggable":"true"}); /*设置一个开关用来设置元素拖到的时候为打开,停止拖动的时候就关闭*/ $(this).attr({"onOff":"false"}); $(this).get(0).ondragstart = function(ev){// console.log("拖动开始"); $(this).attr({"onOff":"true"}); ev.dataTransfer.setData("name","");// console.log($(this).attr("onOff")); }; $(this).get(0).ondragend = function(){ $(this).attr({"onOff":"false"});// console.log("拖动结束"); $(this).attr("class",""); }; }); /*设置接收区域*/ //拖拽进去阻止默认事件 $(".box2").get(0).ondragenter = function(e){// console.log("拖拽进来"); e.preventDefault(); }; //拖拽在里面运动的时候阻止默认事件 $(".box2").get(0).ondragover = function(e){// console.log("在里面运动"); e.preventDefault(); }; //拖拽离开的时候 $(".box2").get(0).ondragleave = function(e){// console.log("拖拽离开"); e.preventDefault(); }; /*拖拽投放的时候*/ $(".box2").get(0).ondrop = function(e){ e.preventDefault(); //判断被拖的元素是不是属于拖动的情况下 $(".box1 ul li").each(function(){ if($(this).attr("onOff") == "true"){ $(".box2 ul").append($(this)); $(this).attr("class",""); }; }); $("box2 ul li").each(function(){ $(this).attr("class",""); }); /*对拖拽进去的元素去除拖拽及开关判断*/// $(".box2 ul li").each(function(index,element){// $(this).removeAttr("draggable").end().removeAttr("onOff");// }); }; $(".box2 ul li").each(function(index,element){ $(this).attr({"draggable":"true"}); /*设置一个开关用来设置元素拖到的时候为打开,停止拖动的时候就关闭*/ $(this).attr({"onOff":"false"}); $(this).get(0).ondragstart = function(ev){// console.log("拖动开始"); $(this).attr({"onOff":"true"}); ev.dataTransfer.setData("name","");// console.log($(this).attr("onOff")); }; $(this).get(0).ondragend = function(){ $(this).attr({"onOff":"false","class":""});// console.log("拖动结束"); }; }); /*设置接收区域*/ //拖拽进去阻止默认事件 $(".box1").get(0).ondragenter = function(e){// console.log("拖拽进来"); e.preventDefault(); }; //拖拽在里面运动的时候阻止默认事件 $(".box1").get(0).ondragover = function(e){// console.log("在里面运动"); e.preventDefault(); }; //拖拽离开的时候 $(".box1").get(0).ondragleave = function(e){// console.log("拖拽离开"); e.preventDefault(); }; /*拖拽投放的时候*/ $(".box1").get(0).ondrop = function(e){ e.preventDefault(); //判断被拖的元素是不是属于拖动的情况下 $(".box2 ul li").each(function(){ if($(this).attr("onOff") == "true"){ $(".box1 ul").append($(this)); }; $(this).attr("class",""); }); $(".box1 ul li").each(function(index,element){ $(this).attr("class",""); }); /*对拖拽进去的元素去除拖拽及开关判断*/// $(".box1 ul li").each(function(index,element){// $(this).removeAttr("draggable").end().removeAttr("onOff");// }); }; /*---------------按钮切换js开始----------------*/ $(".box1 li,.box2 li").on("click",function(){ $(this).toggleClass("active"); }); $(".box3 li").click(function(){ /** * $(this)==$(".box"3 li) * * */ $($(this).attr("from")).find("li.active").appendTo( $(this).attr("to")+" ul").attr("class",""); }); }); })(jQuery); </script></html>
1 0
- 关于常见的左右赋权限的移动样式
- jQuery学习14---权限的左右移动
- 关于列表中内容的左右移动
- 移动端常见的文本框输入样式
- 左右移动的图片
- 左右移动的表格
- 字符串的左右移动
- 赋权限给oralce新建的用户
- 一个左右移动的控件
- 字符的左右移动-java
- 常见的样式
- 常见的样式
- 关于字符串赋初值的错误
- 关于移动端清除下拉菜单的默认样式
- 左右对齐,form-inline样式的使用
- oracle创建只读权限的用户简单四步走(创建用户/赋连接权限/赋表权限/创建同义词)
- 左右的移动<<>><>jQuery的实现
- Mysql中建账号和赋权限的方法
- Iterator 集合的迭代
- JavaScript基础语法介绍
- 混合硬盘装双系统
- MySQL日志介绍
- Ubuntu16.04 server使用Vundle安装vim插件
- 关于常见的左右赋权限的移动样式
- MySQL性能优化基本概念
- 最简单企业证书部署应用!In-House改进版!免HTTPS!
- 在表单提交和链接跳转时弹出确认框
- udp协议之server.c/client.c 源代码分析
- 检测document.getElementsByClassName 兼容性代码
- c指针
- 矩阵顺时针旋转
- iputils软件包简介