博客列表 >2019.5.8作业

2019.5.8作业

关超的博客
关超的博客原创
2019年05月09日 15:32:46565浏览

QQ图片20190509153145.png

<html>
<head>
    <meta charset="UTF-8">
    <title>轮播图</title>
    <style type="text/css">
        .box {
            width: 500px;
            height: 700px;
            background-color: #efefef;
            border: 1px solid lightgray;
            margin: 20px auto;
            text-align: center;
            color: #636363;
            box-shadow: 2px 2px 2px #999;
        }
        .box ul {
            margin:0;
            padding:0;
            /*将ul转为BFC独立块,使之不受内部浮动元素的影响*/
            overflow: hidden;
        }
        .box ul li {
            list-style-type: none;
            float:left;
            background-color: skyblue;
            margin-left: 55px;
        }

        .box ul li a {
            display: block;
            width: 100px;
            height: 40px;
            line-height: 40px;
            color: white;
            text-decoration: none;
        }
        .box ul li:hover {
            font-size:1.2em;
            background-color: coral;
        }

        .active {
            font-size:1.2em;
            background-color: coral;
        }

        .box .pic {
            width: 450px;
            height:450px;
            border: 1px solid lightgray;
            margin: 50px auto 0;
        }

        .box .pic img {
            width: 100%;
            height: 100%;
        }

    </style>
</head>
<body>
<div class="box">
    <h2>景色欣赏</h2>
    <ul>
        <li>
            <a href="yw.jpg" title="夜晚的景色.....">夜色</a>
        </li>
        <li>
            <a href="yw2.jpg" title="日出的景色......">日出</a>
        </li>
        <li>
            <a href="yw3.jpg" title="小岛周边景色......">小岛</a>
        </li>        
    </ul>
    <div class="pic">
        <img src="images/zwt.png" alt="" id="img">
    </div>
    <p id='info'></p>
</div>

<script>
    var pic = document.getElementsByTagName('a');
    var img = document.getElementById('img');
    var p = document.getElementById('info');
       
    for (var i = 0; i < pic.length; i++) {
        pic[i].onclick = function () {
            for (var i = 0; i < pic.length; i++) {
                pic[i].classList.remove('active');
            }
            this.classList.add('active');

            var picUrl = this.href;
            var picInfo = this.title;
            var picName = this.innerHTML;

            img.src = picUrl;
            p.innerHTML = '<span style="color:coral">'+picName+':'+picInfo+'</span>';
            return  false;
        };
    }
</script>
</body>
</html>



声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议