JS原生雙欄穿梭選擇框的實(shí)現(xiàn)示例
何時(shí)使用
用直觀的方式在兩欄中移動(dòng)元素,完成選擇行為。
選擇一個(gè)或以上的選項(xiàng)后,點(diǎn)擊對(duì)應(yīng)的方向鍵,可以把選中的選項(xiàng)移動(dòng)到另一欄。 其中,左邊一欄為 source
,右邊一欄為 target
,API 的設(shè)計(jì)也反映了這兩個(gè)概念。
話不多說(shuō),上代碼。
結(jié)構(gòu)分支
代碼
dataSelection.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>雙欄穿梭選擇框</title> <link rel="stylesheet" href="css/dS.css" rel="external nofollow" > <script src="js/jquery.min.js"></script> <style> body { /*background:#000c3b;*/ } </style> </head> <body> <div style="margin:40px;"> <ul id="shuttle_box"> <li class="shuttle_box_li shuttle_box_near"> <ul id="shuttle_box_left"> <li class="outside">李白 <input type="date" class="inside" style="width:150px;"/> </li> <li class="outside">蘇軾 <input type="date" class="inside" style="width:150px;"/> </li> <li class="outside">王安石 <input type="date" class="inside" style="width:150px;"/> </li> <li class="outside">李商隱 <input type="date" class="inside" style="width:150px;"/> </li> </ul> </li> <li class="shuttle_box_li" id="shuttle_box_mid"> <button id="shuttle_box_toRight">>></button> <button id="shuttle_box_toLeft"><<</button> </li> <li class="shuttle_box_li shuttle_box_near"> <ul id="shuttle_box_right"> <li>王維 <input type="date" class="inside" style="width:150px;"/> </li> </ul> </li> </ul> </div> <script src="js/ds.js"></script> </body> </html>
dS.css
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, p, blockquote, th, td { margin:0; padding:0; list-style: none; } body{background-color: #e3e3e3;margin: 0px;} #shuttle_box{width:700px;zoom: 1;margin: 0px auto;} #shuttle_box:after{ content: "."; clear: both; display: block; height: 0; overflow: hidden; visibility: hidden; } .shuttle_box_li{height: 540px;float: left;} .shuttle_box_near{width:300px;background-color:#ffffff;overflow-y: scroll;overflow-x:hidden;border-radius: 10px;border:5px solid #f4f4f4} .shuttle_box_li_act{color:#ffffff !important;background-color: #009688 !important;border-bottom: 1px solid #ffffff;transition: all .01s;} .shuttle_box_near::-webkit-scrollbar {/*滾動(dòng)條整體樣式*/ width: 6px; /*高寬分別對(duì)應(yīng)橫豎滾動(dòng)條的尺寸*/ height: 1px; } .shuttle_box_near::-webkit-scrollbar-thumb {/*滾動(dòng)條里面小方塊*/ border-radius: 20px; background-color: rgba(0,0,0,0.5); } .shuttle_box_near::-webkit-scrollbar-track {/*滾動(dòng)條里面軌道*/ background-color: rgba(0,0,0,0.2); border-radius: 20px; } .shuttle_box_near li{ padding:8px; border-bottom: 1px solid #ffffff; background-color: #f4f4f4; cursor: pointer; transition: all .5s; } .shuttle_box_li_act:hover{opacity: 0.7;transition: all .01s;} #shuttle_box_mid{width:80px;text-align: center;} #shuttle_box_mid button{ width: 50px; height:30px; display: block; margin:20px auto; line-height: 30px; color:white; cursor: pointer; background-color: #009688; border-radius: 5px; transition: all .5s; border:none; } #shuttle_box_mid button:hover{opacity: 0.7;transition: all .5s;} #shuttle_box_toRight{margin-top:225px !important;}
ds.js
$(document).ready(function() { //穿梭框左側(cè)選中 $("#shuttle_box_left").on('click', 'li', function () { if ($(this).hasClass('shuttle_box_li_act')) { $(this).removeClass('shuttle_box_li_act'); } else { $(this).addClass('shuttle_box_li_act'); } }); //點(diǎn)擊事件選擇內(nèi)部事件 $(".inside").bind('click', function(event1) { event1.stopPropagation(); }); }); //穿梭框右側(cè)選中 $("#shuttle_box_right").on('click', 'li', function () { if ($(this).hasClass('shuttle_box_li_act')) { $(this).removeClass('shuttle_box_li_act'); } else { $(this).addClass('shuttle_box_li_act'); } }); //向右移動(dòng) $("#shuttle_box_toRight").click(function () { if ($("#shuttle_box_left .shuttle_box_li_act").length == 0) return false; $("#shuttle_box_left").find('.shuttle_box_li_act').appendTo("#shuttle_box_right"); $("#shuttle_box_right li").removeClass('shuttle_box_li_act'); }); //向左移動(dòng) $("#shuttle_box_toLeft").click(function () { if ($("#shuttle_box_right .shuttle_box_li_act").length == 0) return false; $("#shuttle_box_right .shuttle_box_li_act").appendTo("#shuttle_box_left"); $("#shuttle_box_left li").removeClass('shuttle_box_li_act'); });
運(yùn)行結(jié)果
到此這篇關(guān)于JS原生雙欄穿梭選擇框的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)JS 雙欄穿梭選擇框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 常見的原始JS選擇器使用方法總結(jié)
- js實(shí)現(xiàn)的全國(guó)省市二級(jí)聯(lián)動(dòng)下拉選擇菜單完整實(shí)例
- javascript 選擇文件夾對(duì)話框(web)
- JS實(shí)現(xiàn)漂亮的時(shí)間選擇框效果
- JS點(diǎn)擊某個(gè)圖標(biāo)或按鈕彈出文件選擇框的實(shí)現(xiàn)代碼
- js實(shí)現(xiàn)一個(gè)省市區(qū)三級(jí)聯(lián)動(dòng)選擇框代碼分享
- js實(shí)現(xiàn)select下拉框選擇
- select下拉選擇框美化實(shí)現(xiàn)代碼(js+css+圖片)
相關(guān)文章
JavaScript字符串的json的自定義加密解密函數(shù)示例
JavaScript自定義函數(shù)中使用String.fromCharCode函數(shù)將輸入字符串中每個(gè)字符的Unicode編碼加1,然后將加密后的字符拼接成一個(gè)新字符串返回,調(diào)用JSON.stringify函數(shù)轉(zhuǎn)換json成一個(gè)普通字符串2023-12-12使用JavaScript和HTML實(shí)現(xiàn)一個(gè)精美的計(jì)算器
計(jì)算器是我們?nèi)粘I钪薪?jīng)常使用的工具之一,可以幫助我們進(jìn)行簡(jiǎn)單的數(shù)學(xué)運(yùn)算,在本博文中,我將使用JavaScript編寫一個(gè)漂亮的計(jì)算器,并添加加減乘除功能,感興趣的同學(xué)可以自己動(dòng)手嘗試一下2023-09-09TypeScript中declare關(guān)鍵字的具體使用
declare關(guān)鍵字用來(lái)告訴編譯器,某個(gè)類型是存在的,可以在當(dāng)前文件中使用,本文主要介紹了TypeScript中declare關(guān)鍵字的具體使用,感興趣的可以了解一下2023-10-10JavaScript判斷一個(gè)URL鏈接是否有效的實(shí)現(xiàn)方法
如何用javascript來(lái)判斷請(qǐng)求的url/鏈接有效(可連接,可用)?需要的朋友可以參考下。2011-10-10JavaScript中的普通函數(shù)和箭頭函數(shù)的區(qū)別和用法詳解
這篇文章主要介紹了JavaScript中的普通函數(shù)和箭頭函數(shù)的區(qū)別和用法詳解,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03學(xué)習(xí)javascript面向?qū)ο?理解javascript原型和原型鏈
這篇文章主要介紹了javascript原型和原型鏈,學(xué)習(xí)javascript面向?qū)ο螅信d趣的小伙伴們可以參考一下2016-01-01