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;

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

  • 相关阅读:
    阿里云mysql远程连不上
    php-fpm的pool php-fpm慢执行日志 open_basedir php-fpm进程管理
    重置mysql密码
    树莓派挂载ntfs优盘
    Nginx安装 默认虚拟主机 Nginx用户认证 Nginx域名重定向
    配置防盗链 访问控制Directory 访问控制FilesMatch
    dash视频服务器本地搭建 (初探)
    npm vue ivew vue-cli3
    一维数组转树形结构
    nginx Access-Control-Allow-Origin 多域名跨域设置
  • 原文地址:https://www.cnblogs.com/Eyrum/p/4562233.html
Copyright © 2011-2022 走看看