• 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之权限管理
    CentOS7使用firewalld打开关闭防火墙与端口
    CentOS 7.2 基于Docker实现MySQL主从架构
    Centos7下安装Docker
    nginx php-fpm安装配置 CentOS编译安装php7.2
    php7的扩展库安装方法
    Android 程序打包及签名
    Message和handler传递对象
    Android AlertDialog去除黑边白边自定义布局(转)
    用MVC做支付宝手机网页支付问题
  • 原文地址:https://www.cnblogs.com/Eyrum/p/4562233.html
Copyright © 2020-2023  润新知