Image Viewer _ javascript techniques built with CSS + JS

Source: Internet
Author: User
The Image Viewer built by CSS + JS is a simple image Viewer built by CSS + JS. You can click the thumbnail to view the large image and view the description of each image separately, the position of the big chart is fixed in width and height. The excess part is hidden. Click the big chart 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





Description of the first big image






  • .
    .
    .


For CSS code, see the demonstration file download at the end of the article.

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 the following to 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:



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.