没有cli的第一个映像

2024-03-28 15:03:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我的图像库有问题。当我点击一个缩略图,它的作品和大图像显示,但我想有第一个图像显示,而不必点击它的缩略图。 我怎样才能解决这个问题? 下面是我的代码。你知道吗

这是我的Django模板:

<div class="row">
    {% if offer_images1 %}
        <div class="col-md-6 col-sm-6 col-xs-12" id="help">
            {% for image in offer_images1 %}
                <img id="imageHere" class="zoom_01 img-responsive" data-zoom-image="{{ image.paint.url }}" />
            {% endfor %}
        </div>

        <div class="col-md-6 col-sm-6 col-xs-12">
            <i><b>{% trans "Title" %}: </b>{{ offer_gallery.title }}</i><br>
            <i><b>{% trans "Status" %}: </b>{{ offer_gallery.status }}</i><br>
        </div>

                {% for image in offer_images1 %}
                    <div class="col-md-3 hover08 column">
                        <div style="padding-top:20px;padding-bottom:20px;">
                            <figure class="img1">
                                <img class="thumb img-responsive" src="{{ image.paint.url }}" width="150" height="150" style="border:1px solid grey">
                            </figure>
                        </div>
                    </div>
                    {% if forloop.counter|divisibleby:"4" and not forloop.last %}
                        </div><div class="row">
                    {% endif %}
                {% endfor %}

    {% endif %}
</div>

以下是我的jQuery代码:

<script>
    $(document).ready(function () {
        $( ".thumb" ).each(function(index) {
            $(this).on("click", function(){
                var image = $(this).attr("src")
                $("#imageHere").attr('src', image);
            });
        });
    });
</script>

Tags: 代码图像imagedivsrcimgiffunction
1条回答
网友
1楼 · 发布于 2024-03-28 15:03:05

在第一个映像上自己触发click事件。你知道吗

<script>
    $(document).ready(function () {

        $(".thumb").on("click", function(){
            $("#imageHere").attr('src', $(this).attr("src"));
        });

        // ======= HERE =======
        $( ".thumb:first" ).click();

    });
</script>

相关问题 更多 >