zoukankan      html  css  js  c++  java
  • javascript平时例子⑩(表情发送)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
    *{
    margin: 0;
    padding: 0;
    }

    #div1 {
    500px;
    height: 200px;
    overflow-y: scroll;
    border: 1px solid black;
    }
    #div1 img{

    }
    #Imgs {
    500px;
    list-style: none;
    margin-left: 5px;
    margin-top: 5px;
    display: none;
    }
    #Imgs li{
    float: left;
    border: 1px solid black;
    margin-top: -1px;
    margin-left: -1px;
    }
    #Imgs li img{
    50px;
    height: 50px;
    }
    </style>
    </head>

    <body>
    <div id="div1"></div>
    <input type="button" value="发送表情" id="btn_Send" />
    <ul id="Imgs">
    </ul>
    <script>
    var ul;
    var div1;
    var divHeight;
    window.onload = function() {
    ul = document.getElementById("Imgs");
    div1=document.getElementById("div1");
    divHeight=div1.offsetHeight;
    var arr = [
    ["1.gif", "得瑟"],
    ["10.gif", "得瑟"],
    ["11.gif", "得瑟"],
    ["12.gif", "得瑟"],
    ["13.jpg", "得瑟"],
    ["14.gif", "得瑟"],
    ["15.gif", "得瑟"],
    ["16.gif", "得瑟"],
    ["17.jpg", "得瑟"],
    ["18.jpg", "得瑟"],
    ["19.gif", "得瑟"],
    ["2.gif", "得瑟"],
    ["21.jpg", "得瑟"],
    ["22.jpg", "得瑟"],
    ["20.gif", "得瑟"],
    ["3.gif", "得瑟"],
    ["5.gif", "得瑟"],
    ["4.gif", "得瑟"],
    ["6.gif", "得瑟"],
    ["7.gif", "得瑟"],
    ["8.gif", "得瑟"],
    ["9.gif", "得瑟"]
    ];

    for(var i=0,len=arr.length;i<len;i++){
    var li = document.createElement("li");
    var img = document.createElement("img");
    img.src = "img/"+arr[i][0];
    img.setAttribute("alt", "表情");
    img.setAttribute("title", arr[i][1]);
    img.onclick=ImgClick;
    li.appendChild(img);
    ul.appendChild(li);
    }

    document.getElementById("btn_Send").onclick=function(){

    ul.style.display="block";

    }

    }

    function ImgClick(e){
    var oEvent=window.event||e;
    var img=oEvent.srcElement||oEvent.target;
    var img1=document.createElement("img");
    img1.src=img.src;
    img1.title=img.title;
    img1.setAttribute("alt",img.getAttribute("alt"));
    img1.width="50";
    img1.height="50";
    img1.style.display="block";
    document.getElementById("div1").appendChild(img1);
    ul.style.display="none";
    divScroll();
    }
    //滚动条滚动距离
    function divScroll(){
    var divChild=div1.childNodes;
    var height=0;
    for(var i=0,len=divChild.length;i<len;i++){
    height+=divChild[i].offsetHeight;

    }
    console.log(height-divHeight);
    document.getElementById("div1").scrollTop=height-divHeight;
    }

    </script>
    </body>
    </html>

  • 相关阅读:
    Docker | 第二章:第一个Docker应用
    Docker | 第一章:Docker简介
    Docker | 第零章:前言
    SpringBoot | 第十五章:基于Postman的RESTful接口测试
    SpringBoot | 第十四章:基于Docker的简单部署
    SpringBoot | 第十三章:测试相关(单元测试、性能测试)
    2014年计划
    学习方法,工作方法 探讨
    2013年总结
    asp.net用Zxing库实现条形码输出
  • 原文地址:https://www.cnblogs.com/cxy66/p/6050953.html
Copyright © 2011-2022 走看看