zoukankan      html  css  js  c++  java
  • gallery

    html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>image Gallery</title>
    <link rel="stylesheet" href="css/layout.css" media="screen">
    </head>
    <body>
    <h1>Snapshots</h1>
    <ul>
    <li><a href="images/a.jpg" title="Lorem ipsum dolor sit amet, consectetur adipisicing elit. " onclick="showPic(this);return false;">test1</a></li>
    <li><a href="images/b.jpg" title="Autem repellendus itaquequi explicabo recusandae." onclick="showPic(this);return false;">test2</a></li>
    <li><a href="images/c.jpg" title=" Quae commodi dolores numquam maxime. Alias, soluta!" onclick="showPic(this);return false;">test3</a></li>
    <li><a href="images/d.jpg" title="facere repudiandae, provident inventore." onclick="showPic(this);return false;">test4</a></li>
    </ul>
    <img id="placeholder" src="images/e.jpg" alt="my image gallery">
    <p id="description">choose an image.</p>
    <script type="text/javascript" src="javascript/showPic.js"></script>
    </body>
    </html>
    
     
    

      

    ---------------------------------------------------------------

    css:

    body{
     300px;
    font-family: "Helvetica","Arial",serif;
    color: #333;
    background-color: #ccc;
    margin: 1em 10%;
    }
    
    h1{
    color:#333;
    background-color: transparent;
    }
    
    a{
    color:#c60;
    background-color: transparent;
    font-weight: bold;
    text-decoration: none;
    }
    
    ul{
    padding: 0;
    }
    
    li{
    float: left;
    padding:1em;
    list-style: none;
    }
    
    image{
    display: block;
    clear: both;
    }
    

      

    ---------------------------------------------------------------

    javascript:

    function showPic(whichpic){
    //获得被点击节点的href属性
    var source=whichpic.getAttribute("href");
    //获得占位节点 placeholder
    var placeholder=document.getElementById("placeholder");
    //设置 placeholder scr=source
    placeholder.setAttribute("src",source);
    
    var text=whichpic.getAttribute("title");
    var description=document.getElementById("description");
    description.firstChild.nodeValue=text;
    }
    
    //获取被点击节点的title属性
    /*var text=whichpic.getAttribute("title");
    alert(text);*/
    //获取描述的节点description
    /*var description=whichpic.getElementById("description");
    description.firstChild.nodeValue=text;*/
    
     
    

      

    ------------------------------------------

    主要是通过getAttribute和setAttribute改变属性改变图片

    在页面通过onclick创建点击事件调用函数showPic(this),this指当前的节点a

    函数showPic(whichpic)的whichpic参数通过this传入

    <img id="placeholder" src="images/e.jpg" alt="my image gallery">

    是占位图片

    <p id="description">choose an image.</p>

    是对占位图片的描述

    根据var text=whichpic.getAttribute("title");获得每张图片的描述

    description.firstChild.nodeValue=text;

    将每张图片的描述的值赋值给占位图片的描述

  • 相关阅读:
    CKEditor 5 摸爬滚打(二)—— 自定义一个简单的加粗插件(上)
    由数组生成对称矩阵
    二终端网络可靠度
    多分类建模评估指标
    linux文本编辑器awk
    sklearn中的pipeline实际应用
    一觉醒来,我掉入计算机之中了···
    一个故事看懂计算机操作系统的进化史
    我是如何把计算机网络考了100分的?
    大一那会,我用QQ远程帮同学考过计算机二级
  • 原文地址:https://www.cnblogs.com/Eyrum/p/4562233.html
Copyright © 2011-2022 走看看