Home >Web Front-end >JS Tutorial >jQuery achieves image preloading effect_jquery

jQuery achieves image preloading effect_jquery

WBOY
WBOYOriginal
2016-05-16 15:29:151513browse

The example in this article describes the jQuery code to implement image preloading effects. Share it with everyone for your reference. The details are as follows:
The screenshot of the running effect is as follows:

The specific code is as follows:

html code:

<div class="main">
  <br>
  <div class="title">图片预加载</div>
  <div class="content">
   <div class="img">
    <a href="">
     <img lazyloadsrc="images/1.jpg" alt="" width="200" height="120">
    </a>
    <span class="loading"></span>
   </div>
   <div class="img">
    <a href="">
     <img lazyloadsrc="images/2.jpg" alt="" width="200" height="120">
    </a>
    <span class="loading"></span>
   </div>
   <div class="img">
    <a href="">
     <img lazyloadsrc="images/3.jpg" alt="" width="200" height="120">
    </a>
    <span class="loading"></span>
   </div>
   <div class="img">
    <a href="">
     <img lazyloadsrc="images/4.jpg" alt="" width="200" height="120">
    </a>
    <span class="loading"></span>
   </div>
   <div class="img">
    <a href="">
     <img lazyloadsrc="images/5.jpg" alt="" width="200" height="120">
    </a>
    <span class="loading"></span>
   </div>
   <div class="img">
    <a href="">
     <img lazyloadsrc="images/6.jpg" alt="" width="200" height="120">
    </a>
    <span class="loading"></span>
   </div>
  </div>
 </div>

js code:

 $(function () {
   $("[lazyLoadSrc]").YdxLazyLoad({
    onShow: function () {
     $(this).parent().next().hide()
    }
   });
 });

You will see this effect when loading images. Now you know the implementation process. I hope you like the jQuery image preloading effect shared by the editor.

Statement:
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