如何使图片库将显示图像更改为缩略图图像?

How can I get the image gallery to change the display image to the thumbnail image?

本文关键字:图像 略图 图片库 显示 显示图 何使      更新时间:2023-09-26

如何将此图片库中的大图更改为缩略图?我似乎不能使它工作。我需要将缩略图的src属性转换为大src属性的值。

<html>
<head>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="CSSChloe.css">
</head>
<body id = "bodyc">
    <div id = "space1">
    </div>
        <div id = "header">
        <div class="image">
        <img src = "Banner.png" alt= " " width="257" height="43" />
        <h4> text</h4>
        </div>
        </div>
        <div id = "space2"> </div>
        <div id= "menuBack">
            <div id= "menu1"><a href="index.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
            <div id= "menu1"><a href="about.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
            <div id= "select"><a href="photo.html" style="text-decoration:none;">           
            <img src = "back.png" alt = " " width = "257" height = "48" style = "position: absolute; left: -14px; top: -5px;" />
            <p id = "menu2" style = "position: absolute; margin-top: 2%;">Photo Gallery</p></a>
            </div>
            <div id= "menu1"><a href="price.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
            <div id= "menu1"><a href="testimontials.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
            <div id= "menu1"><a href="contact.html" style="text-decoration:none;"><p id = "menu2">link</p></a></div>
            <div id= "menu3"><img src ="photographylogo.png" width = "150" height = "125" /></div> 
        </div>
        <div id = "space3"> </div>
        <div id= "content">
        <div style = "width: 60%; height: 100%; float: left;">
        <img id = "big" src ="test1.png" width = "400" height = "350" style = "margin-top: 5%; margin-left: 8%;" />
        </div>
        <div style = "width: 35%; height: 100%; overflow: auto; float:right;">
        <img id = "thumb1" onclick = "thumbFunc('test2.png');" src = "test2.png" width = "150" height = "100" />
        <img id = "thumb2" src = " " width = "150" height = "100" />
        <br/>
        <img id = "thumb3" src = " " width = "150" height = "100" />
        <img id = "thumb4" src = " " width = "150" height = "100" />
        <br/>
        <img id = "thumb5" src = " " width = "150" height = "100" />
        <img id = "thumb6" src = " " width = "150" height = "100" />
        <br/>
        <img id = "thumb7" src = " " width = "150" height = "100" />
        <img id = "thumb8" src = " " width = "150" height = "100" />
        <br/>
        <img id = "thumb9" src = " " width = "150" height = "100" />
        <img id = "thumb10" src = " " width = "150" height = "100" />
        <br/>
        <img id = "thumb11" src = " " width = "150" height = "100" />
        <img id = "thumb12" src = " " width = "150" height = "100" />
        <br/>
        <img id = "thumb13" src = " " width = "150" height = "100" />
        <img id = "thumb14" src = " " width = "150" height = "100" />
        </div>
        </div>
        <script>
        function thumbFunc(a)
        {
        document.getElementById("big").setAttribute(src, a);
        }
        </script>
</body>
</html>

首先,改变内联on-click函数的调用方式:

onclick="thumbFunc('test2.png');"

,所以你不需要再输入图像路径:

onclick="thumbFunc(this.src)"

然后,修改你的javascript:

document.getElementById("big").setAttribute(src, a);

到此(如果您喜欢更简单的方式):

document.getElementById("big").src = a;

或者如果您仍然想坚持使用setAttribute方法,不要忘记将属性(src)与"符号括起来:

document.getElementById("big").setAttribute("src", a);
演示工作