Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="s-page">
  <h1>Загружаем объекты, когда они попадают в видимую область. События: "появление в DOM", resize, scroll, orientationChange</h1>
  <div class="s-list-240">
    <div>
      <div>
        <div>Картинка: 1</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/0.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 2</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/1.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 3</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/2.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 4</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/3.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 5</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/4.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 6</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/5.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 7</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/6.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 8</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/7.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 9</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/8.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 10</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/9.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 11</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/10.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 12</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/11.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 13</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/12.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 14</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/13.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 15</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/14.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 16</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/15.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 17</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/16.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 18</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/17.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 19</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/18.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 20</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/19.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 21</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/20.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 22</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/21.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 23</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/22.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 24</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/23.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 25</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/24.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div>
        <div>Картинка: 26</div>
        <img class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/dem/img/25.gif" s-laz-ere="50" />
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=26" s-laz-ere="50">
        <div>Obj s-laz #26</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=27" s-laz-ere="50">
        <div>Obj s-laz #27</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=28" s-laz-ere="50">
        <div>Obj s-laz #28</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=29" s-laz-ere="50">
        <div>Obj s-laz #29</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=30" s-laz-ere="50">
        <div>Obj s-laz #30</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=31" s-laz-ere="50">
        <div>Obj s-laz #31</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=32" s-laz-ere="50">
        <div>Obj s-laz #32</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=33" s-laz-ere="50">
        <div>Obj s-laz #33</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=34" s-laz-ere="50">
        <div>Obj s-laz #34</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=35" s-laz-ere="50">
        <div>Obj s-laz #35</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=36" s-laz-ere="50">
        <div>Obj s-laz #36</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=37" s-laz-ere="50">
        <div>Obj s-laz #37</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=38" s-laz-ere="50">
        <div>Obj s-laz #38</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=39" s-laz-ere="50">
        <div>Obj s-laz #39</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=40" s-laz-ere="50">
        <div>Obj s-laz #40</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=41" s-laz-ere="50">
        <div>Obj s-laz #41</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=42" s-laz-ere="50">
        <div>Obj s-laz #42</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=43" s-laz-ere="50">
        <div>Obj s-laz #43</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=44" s-laz-ere="50">
        <div>Obj s-laz #44</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=45" s-laz-ere="50">
        <div>Obj s-laz #45</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=46" s-laz-ere="50">
        <div>Obj s-laz #46</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=47" s-laz-ere="50">
        <div>Obj s-laz #47</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=48" s-laz-ere="50">
        <div>Obj s-laz #48</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=49" s-laz-ere="50">
        <div>Obj s-laz #49</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=50" s-laz-ere="50">
        <div>Obj s-laz #50</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=51" s-laz-ere="50">
        <div>Obj s-laz #51</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=52" s-laz-ere="50">
        <div>Obj s-laz #52</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=53" s-laz-ere="50">
        <div>Obj s-laz #53</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=54" s-laz-ere="50">
        <div>Obj s-laz #54</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=55" s-laz-ere="50">
        <div>Obj s-laz #55</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=56" s-laz-ere="50">
        <div>Obj s-laz #56</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=57" s-laz-ere="50">
        <div>Obj s-laz #57</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=58" s-laz-ere="50">
        <div>Obj s-laz #58</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=59" s-laz-ere="50">
        <div>Obj s-laz #59</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=60" s-laz-ere="50">
        <div>Obj s-laz #60</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=61" s-laz-ere="50">
        <div>Obj s-laz #61</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=62" s-laz-ere="50">
        <div>Obj s-laz #62</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=63" s-laz-ere="50">
        <div>Obj s-laz #63</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=64" s-laz-ere="50">
        <div>Obj s-laz #64</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=65" s-laz-ere="50">
        <div>Obj s-laz #65</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=66" s-laz-ere="50">
        <div>Obj s-laz #66</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=67" s-laz-ere="50">
        <div>Obj s-laz #67</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=68" s-laz-ere="50">
        <div>Obj s-laz #68</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=69" s-laz-ere="50">
        <div>Obj s-laz #69</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=70" s-laz-ere="50">
        <div>Obj s-laz #70</div>
      </div>
    </div>
    <div>
      <div class="s-laz" s-laz-url="https://drupala.ru/sites/all/libraries/s-laz/s-laz-loa.php?ind=71" s-laz-ere="50">
        <div>Obj s-laz #71</div>
      </div>
    </div>
  </div>
              
            
!

CSS

              
                /* sla.css */
@keyframes sLaz {
  from {
    opacity: 0.99;
  }
  to {
    opacity: 1;
  }
}

.s-laz {
  animation-duration: 0.001s;
  animation-name: sLaz;
}
/* s-page.css */
.s-page {
  max-width: 1280px;
  padding: 0 0.5rem;
  margin-left: auto;
  margin-right: auto;
}
.s-page {
  background: skyblue;
}
/* s-lis-240.css */
.s-list-180 > * > * {
  background: yellowgreen;
}

.s-list-240 > * > * {
  background: yellowgreen;
}
.s-list-240 {
  display: flex;
  flex-flow: row wrap;
  margin-right: -0.5rem;
  margin-left: -0.5rem;
}

.s-list-240 > * > * {
  margin: 0.5rem;
}

.s-list-240 > * {
  width: 16.66666%;
}

@media all and (max-width: 480px) {
  .s-list-240 > * {
    width: 100%;
  }
}

@media all and (min-width: 481px) and (max-width: 720px) {
  .s-list-240 > * {
    width: 50%;
  }
}

@media all and (min-width: 721px) and (max-width: 960px) {
  .s-list-240 > * {
    width: 33.33333%;
  }
}

@media all and (min-width: 961px) and (max-width: 1200px) {
  .s-list-240 > * {
    width: 25%;
  }
}

@media all and (min-width: 1201px) {
  .s-list-240 > * {
    width: 20%;
  }
}
/* s-laz-dem.css */
div {
  box-sizing: border-box;
}

.s-list-240 > * {
  display: flex;
  align-items: stretch;
}

.s-list-240 > * > *:first-child {
  min-height: 9rem;
  width: calc(100% - 1rem);
}

img.s-laz-pro {
  min-height: 3rem;
}

.s-laz-pro {
  background: transparent
    url(https://drupala.ru/sites/all/libraries/s-laz/img/aja-loa-tra.gif) 50%
    50% no-repeat;
}

.s-laz-pro * {
  background: transparent;
}

.s-laz-sta {
  opacity: 0;
}

.s-laz-end {
  opacity: 1;
  transition: opacity 0.5s linear;
}

img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
}
              
            
!

JS

              
                let sLazSetTag = function (nod, res) {
    nod.classList.add('s-laz-sta');
    nod.style.height = window.getComputedStyle(nod).height;
    nod.innerHTML = res;
    let arr = nod.getElementsByTagName('script');
    for (let n = 0; n < arr.length; n++) {
        eval(arr[n].innerHTML);
    }
    nod.style.height = '';
    nod.classList.remove('s-laz-pro');
    nod.classList.remove('s-laz-sta');
    nod.classList.add('s-laz-end');
};
let sLazAja = function (nod, url) {
    let xml = new XMLHttpRequest();
    xml.open("GET", url + ((/\?/).test(url) ? "&" : "?") + (new Date()).getTime(), true);
    xml.send();
    xml.onreadystatechange = function () {
        if (this.readyState === 4 && this.status === 200) {
            sLazSetTag(nod, this.responseText);
        }
    };
};
let sLazImg = function (nod, url) {
    nod.classList.add('s-laz-sta');
    let hei = window.getComputedStyle(nod).height;
    nod.setAttribute('height', hei);
    nod.src = url;
    nod.removeAttribute('height');
    nod.classList.remove('s-laz-pro');
    nod.classList.remove('s-laz-sta');
    nod.classList.add('s-laz-end');
};
let sLazLoaNod = function (nod) {
    let url = nod.getAttribute('s-laz-url');
    nod.classList.remove('s-laz');
    nod.classList.add('s-laz-pro');
    switch (nod.tagName) {
        case 'IMG':
            sLazImg(nod, url);
            break;
        default:
            sLazAja(nod, url);
            break;
    }
};
let sLazIsVisNod = function (nod) {
    let bouCli = nod.getBoundingClientRect();
    let ere = nod.hasAttribute('s-laz-ere') ? parseInt(nod.getAttribute('s-laz-ere'), 10) : 0;
    if (!(bouCli.bottom > (0 - ere) && bouCli.top < (window.innerHeight + ere))) {
        return false;
    }
    if (!(bouCli.right > (0 - ere) && bouCli.left < (window.innerWidth + ere))) {
        return false;
    }
    return true;
};
let sLazAdd = function (eve) {
    if (eve.animationName === 'sLaz') {
        sLazEve();
    }
};
let sLazLoaAll;
let sLazEveExi = false;
let sLazEve = function () {
    if (sLazLoaAll) {
        clearTimeout(sLazLoaAll);
    }
    let sLazObj = document.querySelectorAll(".s-laz");
    sLazLoaAll = setTimeout(function () {
        sLazObj.forEach(function (nod) {
            if (sLazIsVisNod(nod)) {
                sLazLoaNod(nod);
            }
        });
        if (sLazObj.length === 0) {
            document.removeEventListener('scroll', sLazEve);
            window.removeEventListener('resize', sLazEve);
            window.removeEventListener('orientationChange', sLazEve);
            sLazEveExi = false;
        }
        if (sLazObj.length !== 0 && !sLazEveExi) {
            sLazEveExi = true;
            document.addEventListener('scroll', sLazEve);
            window.addEventListener('resize', sLazEve);
            window.addEventListener('orientationChange', sLazEve);
        }
    }, 30);

};
document.addEventListener('animationstart', sLazAdd, false);
document.addEventListener('MSAnimationStart', sLazAdd, false);
document.addEventListener('webkitAnimationStart', sLazAdd, false);
              
            
!
999px

Console