简体   繁体   English

使用 imagesloaded.js 和 php 代码从文件夹导入图像

[英]Use imagesloaded.js with php code that import images from folder

I have the code below in a bootstrap modal that allows me to display the images from a folder on the website These images are loaded with lazyload.js as soon as the modal is opened.我在引导模式中有下面的代码,它允许我显示网站上文件夹中的图像一旦打开模式,这些图像就会用lazyload.js加载。 When one of the six modals is opened, the images appear and it may be that one image is displayed after 1 second and one after 5 seconds, depending on the size of the image.当打开六个模态之一时,会出现图像,根据图像的大小,可能会在 1 秒后显示一个图像,在 5 秒后显示一个图像。 I want to update the whole thing with loadedimages, so that a loading.gif is displayed, so that the website user can see that something is still coming.我想用loadedimages 更新整个东西,以便显示一个loading.gif,这样网站用户就可以看到一些东西还在发生。 I don't know much about how to do this with loading.gif.我不太了解如何使用 loading.gif 执行此操作。 If you have a better solution, I'm open for ideas.如果您有更好的解决方案,我愿意提供想法。

Modal 1模态1

<div class="portfolio-modal modal fade" id="portfolioModal1" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="close-modal" data-dismiss="modal">
        <div class="lr">
          <div class="rl"></div>
        </div>
      </div>
      <div class="container">
        <div class="row">
          <div class="col-lg-8 mx-auto">
            <div class="modal-body se-pre-con">
              <!-- Project Details Go Here -->
              <h2 class="">AugenBlick</h2>
              <ul class="ul-li" id="container1">
                <?php
                      $thumbs = glob("img/Gallery/AugenBlick/*.*");
                      $images = glob("img/Gallery/AugenBlick/*.*");
                      for ($i=1; $i<count($thumbs); $i++)
                      {
                      $numT = $thumbs[$i];
                      $numI = $images[$i];
                      echo '<li data-src="'.$numT.'"><img class="imggallery lazy" data-src="'.$numT.'" alt=""/></li>';
                      }
                  ?>
              </ul><br>
              <!--<ul class="list-inline">
                <li>Date: January 2017</li>
                <li>Client: Threads</li>
                <li>Category: Illustration</li>
              </ul>-->
              <!--<button class="btn btn-primary" data-dismiss="modal" type="button">
                <i class="fas fa-times"></i>
                Projekt schliessen</button>-->
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

and here the code from loadingimages这里是 loadingimages 的代码

$("#container1, #container2, #container3, #container4, #container5, #container6")
  .imagesLoaded()
  .always(function (instance) {
    console.log("all images loaded");
  })
  .done(function (instance) {
    console.log("all images successfully loaded");
  })
  .fail(function () {
    console.log("all images loaded, at least one is broken");
  })
  .progress(function (instance, image) {
    var result = image.isLoaded ? "loaded" : "broken";
    console.log("image is " + result + " for " + image.img.src);
  });


I didn't understand much because there is none libraries you say, but there is two points:我不太明白,因为你说的没有库,但有两点:
1- in first code block, you loaded image with php. 1- 在第一个代码块中,您使用 php 加载了图像。 and php codes always run before any client side codes like html, css etc. so if you want to do something client side, don't do it with PHP. and php codes always run before any client side codes like html, css etc. so if you want to do something client side, don't do it with PHP.

2- in second codes, there is a response function for.imagesLoaded named.progress meaning the inside codes run when image is loading. 2- 在第二个代码中,有一个响应 function for.imagesLoaded named.progress 表示加载图像时内部代码运行。 so you can do wat you want in this.所以你可以做你想做的事情。
for example, add this loading div to you html:例如,将此加载 div 添加到您的 html:

<style>
.loadingBG{
position: fixed;
top: 0;
left: 0;
background: rgba(0,0,0,0.4);
width: 100%;
height: 100vh;
display: none;
z-index: 100;
}.loaderGIF{
z-index: 101;
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
<div class="loadingBG">
<img src="loader.gif" class="loaderGIF"/>
</div>

and change imageloader.js to this:并将 imageloader.js 更改为:

$("#container1, #container2, #container3, #container4, #container5, #container6")
  .imagesLoaded()
  .always(function (instance) {
    console.log("all images loaded");
  })
  .done(function (instance) {
    console.log("all images successfully loaded");
    $('.loaingBG').fadeOut('slow');
  })
  .fail(function () {
    console.log("all images loaded, at least one is broken");
  })
  .progress(function (instance, image) {
    var result = image.isLoaded ? "loaded" : "broken";
    console.log("image is " + result + " for " + image.img.src);
    $('.loaingBG').fadeIn('slow');
  });

Again, I apologize if it was not relevant because the article was not well expressed.再次,如果它不相关,我很抱歉,因为这篇文章没有很好地表达。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM