Blogger Information
Blog 18
fans 0
comment 0
visits 9848
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS获取元素与DOM操作05-08
偏执的博客
Original
805 people have browsed it
  1. 打开网页效果

    微信图片_20190525212820.png

2.点击京杭大运河效果

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>杭州</title>
    <style>
        .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: 20px;

        }

        .box ul li a {
            /*将a转为块元素,并设置为li的宽高,这样可以使整个li可以被点击*/
            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;
        }

        .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">
    <h1>杭州市景点</h1>
    <ul>
        <li><a href="image/xh.jpg" title="位于浙江省杭州市西湖区龙井路1号,杭州市区西部,景区总面积49平方千米,汇水面积为21.22平方千米,湖面面积为6.38平方千米。" onclick="changePic(this);return false">西湖</a></li>
        <li><a href="image/lft.jpg" title="又名皇妃塔、西关砖塔,位于浙江省会杭州市西湖风景区南岸夕照山的雷峰上。" onclick="changePic(this);return false">雷峰塔</a></li>
        <li><a href="image/lys.jpg" title="又名云林寺,位于浙江省杭州市,背靠北高峰,面朝飞来峰,始建于东晋咸和元年(326年)。" onclick="changePic(this);return false">灵隐寺</a></li>
        <li><a href="image/jhdyh.jpg" title="是世界上里程最长、工程最大的古代运河,也是最古老的运河之一,是中国古代劳动人民创造的一项伟大工程,是中国文化地位的象征之一。" onclick="changePic(this);return false">京杭大运河</a></li>
    </ul>
    <div class="pic">
        <img src="" alt="" id="img">

    </div>
    <p id='info'></p>
</div>
<script>
   var lis = document.getElementsByTagName('a');
   var img = document.getElementById('img');
   var info = document.getElementById('info');

   for (var i = 0;i < lis.length;i++){
       lis[i].onclick=function(ev) {
           for (var j = 0; j < lis.length;j++){
               lis[j].classList.remove('active');
           }
         this.classList.add('active');

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

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

运行实例 »

点击 "运行实例" 按钮查看在线实例

微信图片_20190525212830.png

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post