使用jQuery實(shí)現(xiàn)簡(jiǎn)單穿梭框方式
jQuery實(shí)現(xiàn)穿梭框
項(xiàng)目需要,做個(gè)簡(jiǎn)單的穿梭框****效果圖如下

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>穿梭框</title>
<link rel="stylesheet" href="index.css" rel="external nofollow" >
<script src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<ul id="shuttle_box">
<li class="shuttle_box_li shuttle_box_near">
<ul id="shuttle_box_left">
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</li>
<li>上海市人民廣場(chǎng)</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>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
<li>上海市徐涇東</li>
</ul>
</li>
</ul>
<script src="index.js"></script>
</body>
</html>
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:800px;zoom: 1;margin: 100px 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;}
.shuttle_box_li_act{color:#ffffff !important;background-color: #1890ff !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: #1890ff;
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;}
//穿梭框左側(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');
}
});
//穿梭框右側(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');
});
jQuery穿梭框,可上下左右,全選移動(dòng)
HTML部分
<table align="center" cellpadding="0" cellspacing="0"> ?? ??? ??? ?<tr> ?? ??? ??? ??? ?<td> ?? ??? ??? ??? ??? ?可選擇表項(xiàng) ?? ??? ??? ??? ?</td> ?? ??? ??? ??? ?<td></td> ?? ??? ??? ??? ?<td> ?? ??? ??? ??? ??? ?已選擇表項(xiàng) ?? ??? ??? ??? ?</td> ?? ??? ??? ?</tr> ?? ??? ??? ?<tr> ?? ??? ??? ??? ?<td> ?? ??? ??? ??? ??? ?<select multiple="multiple" id="leftselect" name="leftselect" ?? ??? ??? ??? ??? ??? ?style="width: 100px; height: 160px;"> ?? ??? ??? ??? ??? ??? ?<option value="1"> ?? ??? ??? ??? ??? ??? ??? ?選項(xiàng)1 ?? ??? ??? ??? ??? ??? ?</option> ?? ??? ??? ??? ??? ??? ?<option value="2"> ?? ??? ??? ??? ??? ??? ??? ?選項(xiàng)2 ?? ??? ??? ??? ??? ??? ?</option> ?? ??? ??? ??? ??? ??? ?<option value="3"> ?? ??? ??? ??? ??? ??? ??? ?選項(xiàng)3 ?? ??? ??? ??? ??? ??? ?</option> ?? ??? ??? ??? ??? ??? ?<option value="4"> ?? ??? ??? ??? ??? ??? ??? ?選項(xiàng)4 ?? ??? ??? ??? ??? ??? ?</option> ?? ??? ??? ??? ??? ??? ?<option value="5"> ?? ??? ??? ??? ??? ??? ??? ?選項(xiàng)5 ?? ??? ??? ??? ??? ??? ?</option> ?? ??? ??? ??? ??? ??? ?<option value="6"> ?? ??? ??? ??? ??? ??? ??? ?選項(xiàng)6 ?? ??? ??? ??? ??? ??? ?</option> ?? ??? ??? ??? ??? ??? ?<option value="7"> ?? ??? ??? ??? ??? ??? ??? ?選項(xiàng)7 ?? ??? ??? ??? ??? ??? ?</option> ?? ??? ??? ??? ??? ??? ?<option value="8"> ?? ??? ??? ??? ??? ??? ??? ?選項(xiàng)8 ?? ??? ??? ??? ??? ??? ?</option> ?? ??? ??? ??? ??? ?</select> ?? ??? ??? ??? ?</td> ?? ??? ??? ??? ?<td> ?? ??? ??? ??? ??? ?<input type="button" class="button" id="add" value="選中向右" width="6"> ?? ??? ??? ??? ??? ?<br> ?? ??? ??? ??? ??? ?<input type="button" class="button" id="remove" value="選中向左"> ?? ??? ??? ??? ??? ?<br> ?? ??? ??? ??? ??? ?<input type="button" class="button" id="alladd" value="全部向右"> ?? ??? ??? ??? ??? ?<br> ?? ??? ??? ??? ??? ?<input type="button" class="button" id="allremove" value="全部向左"> ?? ??? ??? ??? ?</td> ?? ??? ??? ??? ?<td> ?? ??? ??? ??? ??? ?<select multiple="multiple" id="rightselect" name="rightselect" ?? ??? ??? ??? ??? ??? ?style="width: 100px; height: 160px;"> ?? ??? ??? ??? ??? ?</select> ?? ??? ??? ??? ?</td> ?? ??? ??? ?</tr> ?? ??? ??? ?<tr> ?? ??? ??? ??? ?<td align="center"> ?? ??? ??? ??? ??? ?<input id="left_up" ?class="button" type="button" value="向上" /> ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?<input id="left_down" class="button" type="button" value="向下" /> ?? ??? ??? ??? ?</td> ?? ??? ??? ??? ?<td></td> ?? ??? ??? ??? ?<td align="center"> ?? ??? ??? ??? ??? ?<input id="right_up" ?class="button" type="button" value="向上" /> ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ?<input id="right_down" class="button" type="button" value="向下" /> ?? ??? ??? ??? ?</td> ?? ??? ??? ?</tr> ?? ??? ?</table>
js部分
//全部向右
$('#alladd').click(function() {
$('#leftselect option').remove().appendTo('#rightselect');
});
//全部向左
$('#allremove').click(function() {
$('#rightselect option').remove().appendTo('#leftselect');
});
//選中向右
$('#add').click(function() {
$('#leftselect option:selected').remove().appendTo('#rightselect');
});
//選中向左
$('#remove').click(function() {
$('#rightselect option:selected').remove().appendTo('#leftselect');
});
//左邊框雙擊向右移動(dòng)
$('#leftselect').dblclick(function() {
$("option:selected", this).remove().appendTo('#rightselect');
});
//右邊框雙擊向右移動(dòng)
$('#rightselect').dblclick(function() {
$("option:selected", this).remove().appendTo('#leftselect');
});
//左邊框往上移動(dòng)
$('#left_up')
.click(
function() {
var index = $('#leftselect option').index(
$('#leftselect option:selected:first'));
var $recent = $('#leftselect option:eq(' + (index - 1) + ')');
if (index > 0) {
var $options = $('#leftselect option:selected')
.remove();
setTimeout(function() {
$recent.before($options)
}, 10);
}
});
//左邊框往下移動(dòng)
$('#left_down')
.click(
function() {
var index = $('#leftselect option').index(
$('#leftselect option:selected:last'));
var len = $('#leftselect option').length - 1;
var $recent = $('#leftselect option:eq(' + (index + 1) + ')');
if (index < len) {
var $options = $('#leftselect option:selected')
.remove();
setTimeout(function() {
$recent.after($options)
}, 10);
}
});
//右邊框往上移動(dòng)
$('#right_up')
.click(
function() {
var index = $('#rightselect option').index(
$('#rightselect option:selected:first'));
var $recent = $('#rightselect option:eq(' + (index - 1) + ')');
if (index > 0) {
var $options = $('#rightselect option:selected')
.remove();
setTimeout(function() {
$recent.before($options)
}, 10);
}
});
//右邊框往下移動(dòng)
$('#right_down')
.click(
function() {
var index = $('#rightselect option').index(
$('#rightselect option:selected:last'));
var len = $('#rightselect option').length - 1;
var $recent = $('#rightselect option:eq(' + (index + 1) + ')');
if (index < len) {
var $options = $('#rightselect option:selected')
.remove();
setTimeout(function() {
$recent.after($options)
}, 10);
}
});
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
EasyUI中實(shí)現(xiàn)form表單提交的示例分享
這里給大家分享的是一段使用EasyUI中實(shí)現(xiàn)form表單提交的方法的核心代碼,小伙伴們根據(jù)自己的需求補(bǔ)全form部分吧,希望大家能夠喜歡。2015-03-03
jquery實(shí)現(xiàn)marquee效果(文字或者圖片的水平垂直滾動(dòng))
原本在前端html代碼中,實(shí)現(xiàn)文字或者圖片的水平垂直滾動(dòng),都是使用的marquee,但隨著考慮瀏覽器的兼容性和符合為w3c的標(biāo)準(zhǔn),接下來(lái)介紹使用Jquery實(shí)現(xiàn)網(wǎng)頁(yè)marquee效果,感興趣的朋友可以了解下哦2013-01-01
jQuery插件之jQuery.Form.js用法實(shí)例分析(附demo示例源碼)
這篇文章主要介紹了jQuery插件之jQuery.Form.js用法,結(jié)合實(shí)例形式分析了jQuery.Form.js的具體使用技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-01-01
用jQuery toggleClass 實(shí)現(xiàn)鼠標(biāo)移上變色
這篇文章主要介紹了用jQuery toggleClass 實(shí)現(xiàn)鼠標(biāo)移上變色,需要的朋友可以參考下2014-05-05
JQuery實(shí)現(xiàn)簡(jiǎn)單的復(fù)選框樹(shù)形結(jié)構(gòu)圖示例【附源碼下載】
這篇文章主要介紹了JQuery實(shí)現(xiàn)簡(jiǎn)單的復(fù)選框樹(shù)形結(jié)構(gòu)圖,涉及jQuery頁(yè)面元素屬性動(dòng)態(tài)操作與事件響應(yīng)相關(guān)操作技巧,并附帶源碼供讀者下載參考,需要的朋友可以參考下2019-07-07
jQuery彈出下拉列表插件(實(shí)現(xiàn)kindeditor的@功能)
這篇文章主要介紹了jQuery彈出下拉列表插件(實(shí)現(xiàn)kindeditor的@功能)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08
關(guān)于jQuery里prev()的簡(jiǎn)單操作代碼
這篇文章主要介紹了jQuery里prev()的簡(jiǎn)單操作代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-10-10
jquery實(shí)現(xiàn)簡(jiǎn)單的拖拽效果實(shí)例兼容所有主流瀏覽器
拖拽效果個(gè)人覺(jué)得是一種不錯(cuò)的用戶(hù)體驗(yàn),抽空研究了一下,原理還蠻簡(jiǎn)單的,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06

