首页 web前端 html教程 Html 制作相册

Html 制作相册

Feb 20, 2017 pm 01:54 PM
html

本文主要讲述采用Html5+jQuery+CSS 制作相册的小小记录。

主要功能点:

  • Html5进行布局

  • 调用jQuery(借用官网的一句话:The Write Less, Do More)极大的简化了JavaScript编程

  • CSS 样式将表现与内容分离

话不多说,先上效果图:

 Html 制作相册

代码如下:

<!DOCTYPE html>
<html>
<head>
    <title>The second html page</title>
    <style type="text/css">
         ul li
        {
            list-style-type:georgian;
            text-align:left;
         }
         body
         {
           margin:10px;
           text-align:center;   
           background-color:Orange;
          }
           header
        {
            height:80px;
            border:1px solid gray;
            width:99%
        }
         .left
        {
            border:1px solid gray;
            float:left;
            width:20%;
            height:520px;
            margin:0px;
            border-top-style:none;
            border-bottom-style:none;
            /*设置边框样式*/
        }
        .main
        {
            width:79%;
            float:left;
            height:520px;
            /*border:1px solid gray;*/
            border-right:1px solid gray;
            margin:0px;
            position:relative;/*设置成相对*/
        }
         footer
        {
            clear:left;
            height:60px;
            border:1px solid gray;
            width:99%
        }
        #container
        {
            display:block;
            padding:5px;
           /* border:1px solid gray;*/
            margin:5px;
            position:relative;
         }
         .small
         {
             display:block;
             border-bottom:1px solid gray;/*将缩略图,和大图隔开*/
         }
         .small img
         {
             width:150px;
             height:120px;
             margin:5px;
             border:1px solid gray;
             padding:3px;
         }
         .mm
         {
             cursor:pointer;
             border-radius:5px;/*鼠标移入样式*/
             
          }
         input[type="button"]
         {
             cursor:pointer;
             background-color:Orange;
             color:Lime;
             font-family:Arial;
             font-size:25px;
             height:50px;
             border:0px;
             width:50px;
             position:relative;
             top:150px;
          }
          #btnLeft
          {
           left:30px; 
           float:left;
          }
           #btnRight
          {
           right:30px;    
           float:right;
          }
    </style>
    <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //初始加载六张图片作为缩略图
            for (var i = 0; i < 6; i++) {
                var src = "img/" + "0" + (i + 1).toString() + ".jpg";
                var img = $("<img />").attr("id", (i + 1).toString()).attr("alt", (i + 1).toString()).attr("src", src);
                $("#small").append(img);
            }
            //设置缩略图的点击事件,以及鼠标移入,移出事件
            $("#small img").click(function () {
                $("#img").css("display", "none");
                var src = $(this).attr("src");
                var alt = $(this).attr("alt");
                var nAlt = parseInt(alt);
                $("#img").attr("alt", nAlt).attr("src", src).fadeIn(delay);
            }).mouseover(function () {
                $(this).addClass("mm");
            }).mouseleave(function () {
                $(this).removeClass("mm");
            });
            var delay = 1000;
            //向左切换事件
            $("#btnLeft").click(function () {
                $("#img").css("display", "none");
                var alt = $("#img").attr("alt");
                if (alt == "1") {
                    alt = 7;
                }
                var nAlt = parseInt(alt) - 1;
                var src = "img/" + "0" + nAlt.toString() + ".jpg";
                $("#img").attr("alt", nAlt).attr("src", src).fadeIn(delay);
            });
            //向右切换事件
            $("#btnRight").click(function () {
                $("#img").css("display", "none");
                var alt = $("#img").attr("alt");
                if (alt == "6") {
                    alt = 0;
                }
                var nAlt = parseInt(alt) + 1;
                var src = "img/" + "0" + nAlt.toString() + ".jpg";
                $("#img").attr("alt", nAlt).attr("src", src).fadeIn(delay);
            });
        });
    </script>
</head>
<body>
<header>
<h2>Html+jQuery + CSS 相册</h2>
</header>
<aside class="left">
<h3>相册说明</h3>
   <ul>
        <li><h4>准备阶段:</h4></li>
        <li>几张图片,最好大小一致,宽高比一致</li>           
        <li>jQuery库文件</li>
    </ul>
    <ul>
        <li><h4>大致思路:</h4></li>
        <li>将界面分<b>上</b>,<b>中</b>(分 <b>左(20%)</b> <b>右(80%)</b>),<b>下</b> 几部分</li>
        <li>实现缩略图,依次放在一个容器中,并设置样式,时间</li>
        <li>实现左右切换的事件函数</li>
    </ul>
</aside>
<section class="main">
    <div class="small" id="small">
   
    </div>
    <div id="container">
        <input type="button" id="btnLeft" value="<<" />
        <img id="img" alt="1" src="img/01.jpg" width="650" height="350" />
        <input type="button" id="btnRight" value=">>" />
    </div>
</section>
<footer>
    <div>This is the footer</div>
</footer>
</body>
</html>
登录后复制

更多Html 制作相册相关文章请关注PHP中文网!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
4 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

HTML 中的表格边框 HTML 中的表格边框 Sep 04, 2024 pm 04:49 PM

HTML 表格边框指南。在这里,我们以 HTML 中的表格边框为例,讨论定义表格边框的多种方法。

HTML 左边距 HTML 左边距 Sep 04, 2024 pm 04:48 PM

HTML 左边距指南。在这里,我们讨论 HTML margin-left 的简要概述及其示例及其代码实现。

HTML 中的嵌套表 HTML 中的嵌套表 Sep 04, 2024 pm 04:49 PM

这是 HTML 中嵌套表的指南。这里我们讨论如何在表中创建表以及相应的示例。

HTML 表格布局 HTML 表格布局 Sep 04, 2024 pm 04:54 PM

HTML 表格布局指南。在这里,我们详细讨论 HTML 表格布局的值以及示例和输出。

HTML 输入占位符 HTML 输入占位符 Sep 04, 2024 pm 04:54 PM

HTML 输入占位符指南。在这里,我们讨论 HTML 输入占位符的示例以及代码和输出。

HTML 有序列表 HTML 有序列表 Sep 04, 2024 pm 04:43 PM

HTML 有序列表指南。在这里我们还分别讨论了 HTML 有序列表和类型的介绍以及它们的示例

在 HTML 中移动文本 在 HTML 中移动文本 Sep 04, 2024 pm 04:45 PM

HTML 中的文本移动指南。在这里我们讨论一下marquee标签如何使用语法和实现示例。

HTML onclick 按钮 HTML onclick 按钮 Sep 04, 2024 pm 04:49 PM

HTML onclick 按钮指南。这里我们分别讨论它们的介绍、工作原理、示例以及各个事件中的onclick事件。

See all articles