개발 창고/Web

[jQuery] How to use Lazy Load

로이제로 2024. 2. 12. 15:50
반응형

 


 Usually, the load on the screen is often longer because once a webpage is floated, it fetches all the content within the page.

 Therefore, even if it is not the screen that the user wants to see (if you simply click on the menu on that page to go to another page, or if you want to click on the content on the current screen without scrolling down), it is often traffic-related because you have to send content that the user does not see. This is especially important for mobile, which needs to be provided at a lower capacity than the web.

 Image accounts for the largest portion of this image, and LazyLoad is one of the ways to reduce the traffic volume of this image.
 This is one of the techniques that requires the image to be imported from the server only if it is currently exposed to the screen.

 Since it is basically a plug-in for jQuery, jQuery must be predefined.

 

Features : LazyLoad

Content  : Technology to reduce load by allowing only scrolled areas to load images

 


How to use

1. Import

<script src="jquery.lazy.min.js" type="text/javascript"></script>

http://jquery.eisbehr.de/lazy/

 

Delayed Content, Image and Background Lazy Loader

Lazy is a fast, feature-rich, extensible and lightweight delayed content loading plugin for jQuery & Zepto.

jquery.eisbehr.de

 

2. Targeting

<img class="lazy" data-original="img/example.jpg" width="640" height="480">

 

3. Apply jQuery

 $(function() {
    $('.lazy').Lazy();
});
OPTION DESCRIPTION EXAMPLE
thresold
The image is displayed from the time when the image is loaded with more than 100 pixels.
thresold:100
placeholder 
If the image is loading, it shows that image.
placeholder:'IMAGE PATH'
effect
Apply the effect to be used when the image is shown.
effect:'fadeIn' 
onError
Process the event if an error occurs while fetching the image
onError:function(ele){}
$('.lazy').Lazy({
    // your configuration goes here
    thresold : 100,
    placeholder : '이미지경로',
    effect: 'fadeIn',
    onError: function(element) {
        console.log('error loading ' + element.data('src'));
    }
});

Reference Site

http://jquery.eisbehr.de/lazy/

 

Delayed Content, Image and Background Lazy Loader

Lazy is a fast, feature-rich, extensible and lightweight delayed content loading plugin for jQuery & Zepto.

jquery.eisbehr.de


[jQuery] Lazy Load 사용하기

🇰🇷 Korean

2020.07.23 - [개발 창고/Web] - [jQuery] Lazy Load 사용하기

 

[jQuery] Lazy Load 사용하기

보통 웹페이지를 한번 띄우면 페이지 내의 모든 콘텐츠를 가져오기 때문에 화면의 로드가 길어지는 경우가 많습니다. 때문에 실제로 사용자가 보고 싶은 화면이 아닌 경우에도 (단순히 해당 페

royzero.tistory.com

 

반응형

'개발 창고 > Web' 카테고리의 다른 글

[jQuery] How to use Datepicker  (33) 2024.03.23
[AWS] S3 버킷 생성  (0) 2023.05.02
[API] NAVER MAPS API 신청하기  (1) 2023.04.13
[Eclipse] docBase를 찾지 못하는 오류  (0) 2023.03.02
[Eclipse] Building workspace (Sleeping)  (0) 2023.03.02