Home > Web Front-end > JS Tutorial > body text

How to use js to achieve the effect of clicking on a small picture to display a large picture? (code example)

藏色散人
Release: 2018-08-11 16:20:45
Original
10621 people have browsed it

This article mainly introduces how to implement js to click on a small picture to display a large picture, that is, js to click on a small picture to preview the big picture. When implementing this function, you will inevitably encounter such requirements during the website construction process. Especially for websites with many images, the display of thumbnails is very important, so it would be an even more efficient display if you can directly click on the small image to preview the large image. js click on the picture to enlarge it is not difficult to operate. Here is a specific code demonstration for you.

js click on the small picture to pop up the specific code example of the big picture as follows:

<div>
    <img  class="dialog" src="1.png" alt="How to use js to achieve the effect of clicking on a small picture to display a large picture? (code example)" >
    <div id="dialog_large_image"></div>
</div>
Copy after login
<script type="text/javascript">
    $(function () {
        $("img.dialog").click(function() {
            var large_image = &#39;<img  src= &#39; + $(this).attr("src") + &#39;</img alt="How to use js to achieve the effect of clicking on a small picture to display a large picture? (code example)" >&#39;;
            $(&#39;#dialog_large_image&#39;).html($(large_image).animate({ height: &#39;50%&#39;, width: &#39;50%&#39; }, 500));
        });
    });
</script>
Copy after login

How to use js to achieve the effect of clicking on a small picture to display a large picture? (code example)

Knowledge points to know here Yes: jQuery event - click() method.

When an element is clicked, the click event occurs.

A click occurs when the mouse pointer stays over an element, and then the left mouse button is pressed and released.

The click() method triggers a click event, or specifies a function to run when a click event occurs.

This article introduces the relevant knowledge about js clicking on the thumbnail to switch to the large image. I hope it will be helpful to friends in need.

【Recommended related articles】

A simple method to use JS to automatically switch images after clicking a button

jquery realizes the special effect of clicking on the picture to view the big picture on the mobile terminal_jquery

JS click on the small picture to associate it with the big picture

Use JS to realize click cycle switching pictures (with code)


The above is the detailed content of How to use js to achieve the effect of clicking on a small picture to display a large picture? (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template