老师你好请检查

来源:5-1 事件参数

weixin_慕粉6116347

2020-03-12 15:22:38

<!DOCTYPE html>

<html>


<head>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>事件参数</title>

    <style type="text/css">

    * {

        margin: 0;

        padding: 0;

    }


    body {

        background: #90B0C7;

    }


    a {

        text-decoration: none;

    }


    span {

        display: block;

        width: 16px;

        height: 16px;

        border-radius: 50%;

        background: #fff;

        margin: 40px auto 45px;

    }


    nav {

        display: flex;

        justify-content: space-between;

        width: 78.124vw;

        margin: 0 auto 45px;

        position: relative;

    }


    nav:before {

        content: '';

        width: 100%;

        height: 15px;

        background: #fff;

        position: absolute;

        top: 17px;

        left: 0;

    }


    nav>a {

        position: relative;

        font-size: 20px;

        padding: 10px;

        background: #fff;

        border: 2px solid #7295AA;

        color: #929BA9;

    }


    div {

        position: relative;

        width: 78.124vw;

        height: 75vh;

        margin: 0 auto;

        background: #fff;

        overflow: hidden;

        box-shadow: 0 0 30px 0 rgba(8, 1, 3, .3);

    }


    div>img {

        width: 98%;

        height: 96%;

        position: absolute;

        top: 0;

        right: 0;

        bottom: 0;

        left: 0;

        margin: auto;

        transition: all 1.5s;

    }


    div>img:not(:first-of-type) {

        opacity: 0;

    }

    </style>

</head>


<body>

    <span></span>

    <nav>

        <a href="#">泸沽湖</a>

        <a href="#">丽江古城</a>

        <a href="#">茶马古道</a>

        <a href="#">就这家·云逸客栈</a>

        <a href="#">西双版纳</a>

        <a href="#">云南红酒庄</a>

        <a href="#">轿子雪山</a>

        <a href="#">普者黑</a>

        <a href="#">海埂大坝</a>

        <a href="#">玉龙湾</a>

        <a href="#">昆明郊野公园</a>

        <a href="#">欧洲风琴小镇</a>

    </nav>

    <div>

        <img src="images/1.jpg">

        <img src="images/2.jpg">

        <img src="images/3.jpg">

        <img src="images/4.jpg">

        <img src="images/5.jpg">

        <img src="images/6.jpg">

        <img src="images/7.jpg">

        <img src="images/8.jpg">

        <img src="images/9.jpg">

        <img src="images/10.jpg">

        <img src="images/11.jpg">

        <img src="images/12.jpg">

    </div>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

    <script type="text/javascript">

    var index = 0;


    $('a').mouseenter(function() {

        index = $(this).index();

        swiper(index);

    })



    //左键37    右键39

    $(document).keydown(function(event) {

        if (event.keyCode == 37) {

            index--;

            if (index < 0) index = 11;

        } else if (event.keyCode == 39) {

            index++;

            if (index > 11) index = 0;

        } else {

            return false;

        }

        swiper(index);

    });



    function swiper(index) {

        $('img').eq(index).css({ 'opacity': '1' }).siblings()

            .css({ 'opacity': '0' });

    }

    </script>

</body>

</html>




我这样子写可以吗?

写回答

1回答

好帮手慕粉

2020-03-12

同学你好,代码实现的是正确的,很棒!继续加油,祝学习愉快~

0

0 学习 · 14456 问题

查看课程

相似问题