First of all, let’s talk about the effect achieved:
1. Picture display and page turning;
2. Click on the picture to enlarge the picture.
The effect achieved is as follows:
Initialization and first picture
Middle image
Last image
Click to enlarge to see image details The content implemented with information
is very simple, it is a regular picture display method. Let’s talk about my implementation ideas.
1. Picture display and page turning
a. Picture display
Picture display is achieved through the tag:
<div> <div> <div id="prev" onclick="updateImage('prev')"></div> <a id="img1" onclick="showImg(1)"> <img class="thumb-img lazy" src="/static/imghwm/default1.png" data-src="img/demopage/thumb-1.jpg" style="max-width:90%" style="max-width:90%" alt=""> </a> <a class="thumb-a thumb-a-hide" onclick="showImg(2)"> <img class="thumb-img lazy" src="/static/imghwm/default1.png" data-src="img/demopage/thumb-2.jpg" style="max-width:90%" style="max-width:90%" alt=""> </a> <a class="thumb-a thumb-a-hide" onclick="showImg(3)"> <img class="thumb-img lazy" src="/static/imghwm/default1.png" data-src="img/demopage/thumb-3.jpg" style="max-width:90%" style="max-width:90%" alt=""> </a> <div id="next"></div> </div> </div>b. Page turning
Page turning is implemented through the updateImage function. The passed parameter is type. It determines the "previous" or "next" during the operation. updateImage The function is as follows:
function updateImage(type){ if(type==="prev"){ if(imgIndex>1){ imgIndex=imgIndex-1; } } else{ if(imgIndexIn the function, imgIndex records the number of the currently displayed image. <p></p> <p>①. Determine the operation type and set the number of the image after the operation. </p> <p>②, add the thumb-a-hide style in a loop, hide all pictures, and remove the thumb-a-hide style with the picture number imgIndex, display the picture; <br> </p> <p>③ , Determine the display and hiding of the operation button based on imgIndex. </p> <p><br> </p> <p>2. Click to display image details and information </p> <p>This effect is achieved through the function showImg. The specific content of showImg is as follows: </p> <p></p> <pre name="code" class="sycode"> function showImg(index){ var width=600,height=400; var winWidth = $(window).width(),winHeight = $(window).height(); var modalBg = $("<div></div>"); modalBg.addClass("modal-bg"); modalBg.appendTo($('body')); var modal = $("<div></div>"); modal.addClass("modal"); modal.css("position","absolute") .css("top",(winHeight-height)/2+"px") .css("left",(winWidth-width)/2+"px"); var titleTipsBg = $("<div></div>").addClass("tips-bg"); var titleTips = $("<a></a>").addClass("tips").html("I am a Chinese."); var titleClose = $("<a></a>").addClass("close"); var title = $("<div></div>"); title.addClass("title"); title.append(titleTipsBg) .append(titleTips) .append(titleClose); titleClose.on("click",function(){ modalBg.hide(); modal.hide(); }); title.appendTo(modal); var img = $("<img src="/static/imghwm/default1.png" data-src="img/demopage/image-1.jpg" class="lazy" alt="CSS JS realizes picture collection display_html/css_WEB-ITnose" >").attr("width",width) .attr("height",height) .attr("src","img/demopage/image-"+index+".jpg"); var imgDiv = $("<div></div>").append(img); imgDiv.appendTo(modal); modal.appendTo($('body')); }
The above code generates the Html code as follows:
<div class="modal-bg"></div><div class="modal" style="max-width:90%"> <div class="title"> <div class="tips-bg"></div> <a class="tips">I am a Chinese.</a> <a class="close"></a> </div> <div> <img src="/static/imghwm/default1.png" data-src="img/demopage/image-1.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="CSS JS realizes picture collection display_html/css_WEB-ITnose" > </div> </div>
In fact, a modal layer is created to display the enlarged image.
Above, the CSS styles involved are as follows:
<style type="text/css"> html, body, .modal-bg { height: 100%; margin: 0; padding: 0; font-size: 13px; font-weight: bold; color: #fff; } .modal-bg{ position: absolute; left: 0px; top: 0px; width: 100%; background: #48525e; opacity: 0.4; z-index: 10; } .modal{ position: relative; z-index: 99; opacity: 1; top: 15%; left: 40%; width: 600px; height: 400px; } .modal .title .tips-bg{ position: absolute; bottom: 0px; left: 0px; background: #48525e; width: 100%; height: 50px; opacity: 0.8; } .modal .title .tips{ position: absolute; bottom: 13px; left: 10px; font-family: "Arial"; font-weight: bold; font-size: 20px; } .modal .title .close{ background: url(img/close.png) no-repeat; width: 27px; height: 27px; position: absolute; top: 5px; right: 5px; } .modal .title .close:hover{ cursor: pointer; } .container{ position: absolute; top: 200px; text-align: center; width: 100%; z-index: 5; } .image-list{ width:300px; margin-left: 40%; position: relative; } #prev{ display: none; position: absolute; top: 55px; left: 35px; float: left; width: 45px; height: 50px; background: url(img/prev.png); } #next{ position: absolute; top: 55px; right: 40px; width: 45px; height: 50px; background: url(img/next.png); } #prev:hover,#next:hover{ cursor: pointer; } .thumb-a{ display:inline-block; padding:4px; margin:0 0.5rem 1rem 0.5rem 1rem; line-height:0; -webkit-transition:background-color 0.1s ease-out; -moz-transition:background-color 0.1s ease-out; -o-transition:background-color 0.1s ease-out; transition:background-color 0.1s ease-out; -webkit-border-radius:6px; -moz-border-radius:6px; -ms-border-radius:6px; -o-border-radius:6px; border-radius:6px } .thumb-a:hover{ background-color:#4ae; cursor: pointer; } .thumb-a-hide{ display: none; } .thumb-img{ -webkit-border-radius:5px; -moz-border-radius:5px; -ms-border-radius:5px; -o-border-radius:5px; border-radius:5px } </style>
At this point, the picture collection display is completed The complete html code is as follows:
Image List <style type="text/css"> html, body, .modal-bg { height: 100%; margin: 0; padding: 0; font-size: 13px; font-weight: bold; color: #fff; } .modal-bg{ position: absolute; left: 0px; top: 0px; width: 100%; background: #48525e; opacity: 0.4; z-index: 10; } .modal{ position: relative; z-index: 99; opacity: 1; top: 15%; left: 40%; width: 600px; height: 400px; } .modal .title .tips-bg{ position: absolute; bottom: 0px; left: 0px; background: #48525e; width: 100%; height: 50px; opacity: 0.8; } .modal .title .tips{ position: absolute; bottom: 13px; left: 10px; font-family: "Arial"; font-weight: bold; font-size: 20px; } .modal .title .close{ background: url(img/close.png) no-repeat; width: 27px; height: 27px; position: absolute; top: 5px; right: 5px; } .modal .title .close:hover{ cursor: pointer; } .container{ position: absolute; top: 200px; text-align: center; width: 100%; z-index: 5; } .image-list{ width:300px; margin-left: 40%; position: relative; } #prev{ display: none; position: absolute; top: 55px; left: 35px; float: left; width: 45px; height: 50px; background: url(img/prev.png); } #next{ position: absolute; top: 55px; right: 40px; width: 45px; height: 50px; background: url(img/next.png); } #prev:hover,#next:hover{ cursor: pointer; } .thumb-a{ display:inline-block; padding:4px; margin:0 0.5rem 1rem 0.5rem 1rem; line-height:0; -webkit-transition:background-color 0.1s ease-out; -moz-transition:background-color 0.1s ease-out; -o-transition:background-color 0.1s ease-out; transition:background-color 0.1s ease-out; -webkit-border-radius:6px; -moz-border-radius:6px; -ms-border-radius:6px; -o-border-radius:6px; border-radius:6px } .thumb-a:hover{ background-color:#4ae; cursor: pointer; } .thumb-a-hide{ display: none; } .thumb-img{ -webkit-border-radius:5px; -moz-border-radius:5px; -ms-border-radius:5px; -o-border-radius:5px; border-radius:5px } </style> <script> var imgIndex = 1; function showImg(index){ var width=600,height=400; var winWidth = $(window).width(),winHeight = $(window).height(); var modalBg = $("<div>"); modalBg.addClass("modal-bg"); modalBg.appendTo($('body')); var modal = $("<div>"); modal.addClass("modal"); modal.css("position","absolute") .css("top",(winHeight-height)/2+"px") .css("left",(winWidth-width)/2+"px"); var titleTipsBg = $("<div>").addClass("tips-bg"); var titleTips = $("<a>").addClass("tips").html("I am a Chinese."); var titleClose = $("<a>").addClass("close"); var title = $("<div>"); title.addClass("title"); title.append(titleTipsBg) .append(titleTips) .append(titleClose); titleClose.on("click",function(){ modalBg.hide(); modal.hide(); }); title.appendTo(modal); var img = $("<img class="thumb-img lazy" src="/static/imghwm/default1.png" data-src="img/demopage/thumb-1.jpg" alt="CSS JS realizes picture collection display_html/css_WEB-ITnose" >").attr("width",width) .attr("height",height) .attr("src","img/demopage/image-"+index+".jpg"); var imgDiv = $("<div>").append(img); imgDiv.appendTo(modal); modal.appendTo($('body')); } function updateImage(type){ if(type==="prev"){ if(imgIndex>1){ imgIndex=imgIndex-1; } } else{ if(imgIndex<3){ imgIndex=imgIndex+1; } } for(var i=0;i<3;i++){ $("#img"+(i+1)).addClass("thumb-a-hide"); } $("#img"+imgIndex).removeClass("thumb-a-hide"); if(imgIndex===3){ $("#next").hide(); } else{ $("#next").show(); } if(imgIndex===1){ $("#prev").hide(); } else{ $("#prev").show(); } }; </script>
If you have any questions, please contact:
QQ: 1004740957
Emai :niujp08@qq.com

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
