Css+js-built picture viewer _javascript Tips

Source: Internet
Author: User

This is a simple picture viewer built using CSS + JS, use thumbnail click to see a large image, you can display each picture description, the larger picture shows the location using fixed width and height, beyond the part of the hidden, click on the big picture can see the full size, Compatibility: IE, Firefox, Opera.

JS part

function Showpic (whichpic) {
if (document.getElementById) {
document.getElementById (' placeholder '). 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 big picture </p>
<DIV id= "Thumbs" >
<ul>
<li><a onclick= "Return Showpic" (this); "href=" The address of the first big picture "title=" >
</a></li>
.
.
.
</ul>
</div>
</div>

CSS code see the end of the article demo file download

Now the effect

Because the big picture display position is fixed size, but the picture each size is different, so the above code runs the result is not ideal, but also must add clicks the big picture to view the complete size code, here uses the good lightbox effect.

In the above JS code to add:

document.getElementById (' Showlightbox '). href = Whichpic.href;

Lightbox need to have a large image address in the a tag.
The head area adds the Lightbox code.

In the XHTML code above, add:

<div id= "pic" > <a href= "The address of the first big picture" 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.