Cookie的选项卡加拖拽。

 Cookie的选项卡加拖拽

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            position: absolute;
            left: 100px;
            top: 100px;
            background: red;
        }
    </style>
</head>

<body>
    <div></div>
</body>
<script>
    var div = document.querySelector('div');
    if (getCookie('mmm')) {
        div.style.left = getCookie('mmm').split(',')[0] + 'px'
        div.style.top = getCookie('mmm').split(',')[1] + 'px'
    }
    div.onmousedown = function (e) {
        var dx = e.pageX - div.offsetLeft
        var dy = e.pageY - div.offsetTop
        document.onmousemove = function (e) {
            var x = e.pageX - dx;
            var y = e.pageY - dy;
            div.style.left = x + 'px'
            div.style.top = y + 'px'
            setCookie('mmm', [x, y], 1000)
        }
        document.onmouseup = function () {
            document.onmousemove = null;
            document.onmouseup = null;
        }
    }
    //添加cookie
    function setCookie(name, value, time) {
        var date = new Date();
        date.setDate(date.getDate() + time);
        document.cookie = name + "=" + value + ";expires=" + date;
    }


    //获得cookie
    function getCookie(name) {
        var arr = document.cookie.split(";");
        for (var i = 0; i < arr.length; i++) {
            var arr2 = arr[i].split("=");
            if (arr2[0] == name) {
                return arr2[1];
            }
        }
        return null;
    }


    //删除cookie
    function removeCookie(name) {
        setCookie(name, "", 0)
    } 
</script>

</html>

下面是Cookie的选项卡

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        ul {
            display: flex;
        }

        ul li {
            width: 100px;
            height: 20px;
            border: 1px solid #000;
        }

        ol li {
            width: 405px;
            height: 300px;
            border: 1px solid #000;
            display: none;
        }

        .uli {
            background: red;
        }

        .oli {
            background: red;
            display: block;
        }
    </style>
</head>

<body>
    <div>
        <ul>
            <li class="uli"></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <ol>
            <li class="oli">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ol>
    </div>
    <script>
        var uli = document.querySelectorAll('ul li')
        var oli = document.querySelectorAll('ol li')
        function bb(index) {
            for (let j = 0; j < uli.length; j++) {
                uli[j].className = '';
                oli[j].className = '';
            }
            uli[index].className = 'uli'
            oli[index].className = 'oli'
        }
        if (getCookie('xxk')) {
            bb(getCookie('xxk') - 0)
        }
        for (let i = 0; i < uli.length; i++) {
            uli[i].index = i;
            uli[i].onclick = function () {
                bb(i)
                setCookie('xxk', this.index, 1000)
            }
        }
        //添加cookie
        function setCookie(name, value, time) {
            var date = new Date();
            date.setDate(date.getDate() + time);
            document.cookie = name + "=" + value + ";expires=" + date;
        }
        //获得cookie
        function getCookie(name) {
            var arr = document.cookie.split(";");
            for (var i = 0; i < arr.length; i++) {
                var arr2 = arr[i].split("=");
                if (arr2[0] == name) {
                    return arr2[1];
                }
            }
            return null;
        }
        //删除cookie
        function removeCookie(name) {
            setCookie(name, "", 0)
        } 
    </script>


</html>

先看后赞再关已成习惯谢谢! 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值