博客列表 >JS基础相册-2018-04-02

JS基础相册-2018-04-02

彪小A的博客
彪小A的博客原创
2018年04月02日 11:38:58511浏览

<!DOCTYPE html>
<html lang="en">
<head>
   <style type="text/css">
       .box{
           width: 500px;
           height: 500px;
           border: 1px solid black;
           margin: auto;
       }
       .header{
           width: 100%;
           height: 50px;
           border-bottom: 1px solid black;
           margin: auto;
           text-align: center;
       }
       .header button{
           width: 100px;
           height:30px;
           margin-top: 10px;
           background-color: coral;
           color: white;
           font-size: 12px;
       }
       .header button:hover{
           font-size: 16px;
           background-color: lightskyblue;
           cursor: pointer;
       }
       .footer{
           width: 100%;
           height: 450px;
           overflow: hidden;
       }
       .footer .img{
           width: 100%;
           height: 350px;
           text-align: center;
           padding: 10px 0;
           border-bottom: 1px solid black;
       }
       .footer .img img{
           width: 95%;
           height: 100%;
       }
       .footer .info{
           width: 100%;
           height: 80px;
           text-align: center;

       }
       .content{
           text-align: left;
           width: 100%;
           float: right;
       }
   </style>
   <meta charset="UTF-8">
   <title>雪橇三傻</title>
</head>
<body>
   <div class="box">
       <div class="header">

           <button onclick="changePic(this)">哈士奇</button>
           <button onclick="changePic(this)">萨摩耶</button>
           <button onclick="changePic(this)">阿拉斯加</button>
       </div>
       <div class="footer">
           <div class="img">
               <img id="img" src="images/placeholder.jpeg" alt="">
           </div>
           <div class="info">
               <span class="content" id="content"></span>
           </div>
       </div>
   </div>
</body>
<script type="text/javascript">
   function changePic(obj) {
       var imageUrl = "images/placeholder.jpeg";
       var info = "";
       switch(obj.innerHTML){
           case '哈士奇':
               imageUrl = "images/hsq.jpg";
               info="西伯利亚雪橇犬是原始的古老犬种,在西伯利亚东北部、格陵兰南部生活。哈士奇名字的由来,是源自其独特的嘶哑声";
               break;
           case '萨摩耶':
               imageUrl = "images/smy.jpg";
               info="萨摩耶犬(英文:Samoyed),别称萨摩耶,原是西伯利亚的原住民萨摩耶族培育出的犬种,一岁前调皮、灵动。";
               break;
           case '阿拉斯加':
               imageUrl = "images/alsj.jpg";
               info="阿拉斯加雪橇犬也叫阿拉斯加犬,它的名字取自爱斯基摩人的伊努伊特族的一个叫做马拉缪特的部落。这个部落生活在阿拉斯加西部一个叫做科策布(Kotzebue)的岸边。";
               break;
       }
       var img = document.getElementById("img");
       img.src = imageUrl;
       var content = document.getElementById("content");
       content.innerHTML = info;

       var name = document.getElementById("name");
       name.innerHTML = obj.innerHTML;
   }
</script>
</html>

效果图

Snip20180402_2.png

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