Image Viewer built with CSS + JS

Source: Internet
Author: User

Image Viewer built with CSS + JS

This is a simple image Viewer built with CSS + Js. You can click a thumbnail to view the large image. The description of each image is displayed. The position of the large image is fixed width and height, and the excess part is hidden, click the big picture to view the full size, compatibility: IE, Firefox, and opera.

JS Section
 
Function showpic (whichpic ){
If (document. getelementbyid ){
Document. getelementbyid ('holder'). src = whichpic. href;
If (whichpic. Title ){
Document. getelementbyid ('desc'). childnodes [0]. nodevalue = whichpic. title;
} Else {
Document. getelementbyid ('desc'). childnodes [0]. nodevalue = whichpic. childnodes [0]. nodevalue;
} Return false;
} Else {
Return true;
}}
XHTML
 
<Div id = "album"> <Div id = "pic">  </ div> <p id = "DESC"> description of the first large image </P> <Div id = "thumbs"> <ul> <li> <a onclick = "Return showpic (This ); "href =" Address of the first large image "Title =" ">  </a> </LI>... </ul> </div>

CSSCodeSeeArticleTerminal demo File Download

Current results

Because the position of the big image is fixed, but the size of each image is different, the running result of the above Code is not ideal. You need to click the big picture to view the full size code, here we use a good lightbox effect.

Add in the above JS Code
 
Document. getelementbyid ('showlightbox'). href = whichpic. href;

Lightbox needs to have a big image address in label ..

Add the lightbox code to the head area.

In the above XHTML code, add
 
<Div id = "pic"> <a href = "Address of the first large image" rel = "lightbox" id = "showlightbox">  </a> </div>

Final Effect

Download all Demo files

Thanks to hooline And Lokesh dhakar 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.