简单穿梭框代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>穿梭框</title>
    <link rel="stylesheet" href="index.css">
    <script src="jquery.min.js"></script>
    <style>
        ul,
        li {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        body {
            background-color: #e3e3e3;
            margin: 0px;
        }

        .box {
            width: 300px;
            background-color: #ffffff;
            height: 240px;
            float: left;
        }

        .Path {
            color: #ffffff !important;
            background-color: #1890ff !important;
            border-bottom: 1px solid #ffffff;
            transition: all .01s;
        }

        .box li {
            padding: 8px;
            border-bottom: 1px solid #ffffff;
            background-color: #f4f4f4;
            cursor: pointer;
            transition: all .5s;
        }

        #btn {
            height: 240px;
            float: left;
            width: 80px;
            text-align: center;
        }

        #btn 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;
        }
    </style>
</head>
<body>
<li class="box">
    <ul id="shuttleLeft">
        <li>王小婷1</li>
        <li>王小婷2</li>
        <li>王小婷3</li>
    </ul>
</li>
<li id="btn">
    <button id="toRight">></button>
    <button id="toLeft"><</button>
</li>
<li class="box">
    <ul id="shuttleRight">
        <li>祈澈菇凉1</li>
        <li>祈澈菇凉2</li>
        <li>祈澈菇凉3</li>
    </ul>
</li>
</body>
<script>
    //穿梭框左侧选中
    $("#shuttleLeft").on('click', 'li', function() {
        if($(this).hasClass('Path')) {
            $(this).removeClass('Path');
        } else {
            $(this).addClass('Path');
        }
    });
    //穿梭框右侧选中
    $("#shuttleRight").on('click', 'li', function() {
        if($(this).hasClass('Path')) {
            $(this).removeClass('Path');
        } else {
            $(this).addClass('Path');
        }
    });
    //向右移动
    $("#toRight").click(function() {
        if($("#shuttleLeft .Path").length == 0) return false;

        $("#shuttleLeft").find('.Path').appendTo("#shuttleRight");
        $("#shuttleRight li").removeClass('Path');
    });
    //向左移动
    $("#toLeft").click(function() {
        if($("#shuttleRight .Path").length == 0) return false;
        $("#shuttleRight .Path").appendTo("#shuttleLeft");
        $("#shuttleLeft li").removeClass('Path');
    });
</script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值