jQuery实现穿梭框

需求:点击选中左侧内容,把左侧的内容放到右侧的框里面,可以一次放入一个,也可以一次放入多个或者全部,同样,右侧也一样。

写了一个简单的demo,仅供参考:


   
   
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>穿梭框 </title>
  6. <link rel="stylesheet" href="index.css">
  7. <script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"> </script>
  8. <style>
  9. ul,
  10. li {
  11. margin: 0;
  12. padding: 0;
  13. list-style: none;
  14. }
  15. body {
  16. background-color: #e3e3e3;
  17. margin: 0px;
  18. }
  19. .box {
  20. width: 300px;
  21. background-color: #ffffff;
  22. height: 240px;
  23. float: left;
  24. }
  25. .Path {
  26. color: #ffffff !important;
  27. background-color: #1890ff !important;
  28. border-bottom: 1px solid #ffffff;
  29. transition: all . 01s;
  30. }
  31. .box li {
  32. padding: 8px;
  33. border-bottom: 1px solid #ffffff;
  34. background-color: #f4f4f4;
  35. cursor: pointer;
  36. transition: all . 5s;
  37. }
  38. #btn {
  39. height: 240px;
  40. float: left;
  41. width: 80px;
  42. text-align: center;
  43. }
  44. #btn button {
  45. width: 50px;
  46. height: 30px;
  47. display: block;
  48. margin: 20px auto;
  49. line-height: 30px;
  50. color: white;
  51. cursor: pointer;
  52. background-color: #1890ff;
  53. border-radius: 5px;
  54. transition: all . 5s;
  55. border: none;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <li class="box">
  61. <ul id="shuttleLeft">
  62. <li>王小婷1 </li>
  63. <li>王小婷2 </li>
  64. <li>王小婷3 </li>
  65. </ul>
  66. </li>
  67. <li id="btn">
  68. <button id="toRight">> </button>
  69. <button id="toLeft"> <</button>
  70. </li>
  71. <li class="box">
  72. <ul id="shuttleRight">
  73. <li>祈澈菇凉1 </li>
  74. <li>祈澈菇凉2 </li>
  75. <li>祈澈菇凉3 </li>
  76. </ul>
  77. </li>
  78. </body>
  79. <script>
  80. //穿梭框左侧选中
  81. $( "#shuttleLeft").on( 'click', 'li', function() {
  82. if($( this).hasClass( 'Path')) {
  83. $( this).removeClass( 'Path');
  84. } else {
  85. $( this).addClass( 'Path');
  86. }
  87. });
  88. //穿梭框右侧选中
  89. $( "#shuttleRight").on( 'click', 'li', function() {
  90. if($( this).hasClass( 'Path')) {
  91. $( this).removeClass( 'Path');
  92. } else {
  93. $( this).addClass( 'Path');
  94. }
  95. });
  96. //向右移动
  97. $( "#toRight").click( function() {
  98. if($( "#shuttleLeft .Path").length == 0) return false;
  99. $( "#shuttleLeft").find( '.Path').appendTo( "#shuttleRight");
  100. $( "#shuttleRight li").removeClass( 'Path');
  101. });
  102. //向左移动
  103. $( "#toLeft").click( function() {
  104. if($( "#shuttleRight .Path").length == 0) return false;
  105. $( "#shuttleRight .Path").appendTo( "#shuttleLeft");
  106. $( "#shuttleLeft li").removeClass( 'Path');
  107. });
  108. </script>
  109. </html>
5640239-ba1a65025258cc4e.png

原文作者:祈澈姑娘 技术博客:https://www.jianshu.com/u/05f416aefbe1
90后前端妹子,爱编程,爱运营,文艺与代码齐飞,魅力与智慧共存的程序媛一枚,欢迎关注【编程微刊】公众号,回复【领取资源】,500G编程学习资源干货免费送。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值