jQuery實現簡單穿梭框


效果圖

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>穿梭框</title>
        <link rel="stylesheet" href="index.css">
        <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>上海市人民廣場</li>
                    <li>上海市人民廣場</li>
                    <li>上海市人民廣場</li>
                    <li>上海市人民廣場</li>
                    <li>上海市人民廣場</li>
                    <li>上海市人民廣場</li>
                    <li>上海市人民廣場</li>
                    <li>上海市人民廣場</li>
                    <li>上海市人民廣場</li>
                    <li>上海市人民廣場</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 {/*滾動條整體樣式*/
       width: 6px;     /*高寬分別對應橫豎滾動條的尺寸*/
       height: 1px;
   }
.shuttle_box_near::-webkit-scrollbar-thumb {/*滾動條里面小方塊*/
       border-radius: 20px;
       background-color: rgba(0,0,0,0.5);
   }
.shuttle_box_near::-webkit-scrollbar-track {/*滾動條里面軌道*/
       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;}
//穿梭框左側選中
$("#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');
    }
});
//穿梭框右側選中
$("#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');
    }
});
//向右移動
$("#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');


});
//向左移動
$("#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');
});

是不是有點兒簡單----哈啊哈,我也覺得

 

 

 

如果你想任性,那就先學會承受,能承受后果才可以任性。如果你想獨立,那就先學會堅強,才可以獨立。如果你想放肆的愛,那就先學會遺忘,只有能忘掉失戀痛楚,才可以大膽愛。你可以去做一切事情,但前提是不會為結果傷悲。一個人真正的強大,並非看他能做什么,而是看他能承擔什么。

勇敢的做自己,不要為任何人而改變。心存希望,幸福就會降臨你;心存夢想,機遇就會籠罩你;心存堅持,快樂就會常伴你;心存真誠,平安就會跟隨你;一旦有了貪欲,就注定要失去。如果你簡單,這個世界就對你簡單。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM