


Detailed description of image lazy loading technology using jquery plug-in_jquery
Here it is recommended to use the jquery image lazy loading plug-in jquery.lazyload to implement delayed image loading and improve website opening speed. Download address: http://www.appelsiini.net/download/jquery.lazyload. js
1. Quick Use Chapter
1. Import JS plug-in
2. Add the following javascript to your page:
This will cause all images to be loaded lazily;
2. Detailed introduction to the advanced chapter (I don’t want to know so much can be bypassed directly)
Lazy Load is a jQuery plug-in written in JavaScript. It can delay loading of images in long pages. Images outside the browser's visible area will not be loaded until the user Scroll the page to where they are. This is the opposite of how image preloading is handled.
Lazy loading of images on long pages with many large images can speed up page loading. The browser will load visible images before After that, it enters the ready state. In some cases, it can also help reduce server load.
Lazy Load is inspired by the YUI ImageLoader toolbox produced by Matt Mlinac.
How to use?
Lazy Load depends on jQuery. Please Add the following code to the page head area:
And add the following statement to your execution code:
$("#xd").lazyload();
This will cause the images under the id="xd" area to be lazy loaded.
Set sensitive The
plug-in provides the threshold option, which can control the loading of images by setting the threshold value (the distance from where the loading is triggered to the image). The default value is 0 (loaded when the image boundary is reached).
view sourceprint?$ ("#xd").lazyload({ threshold : 200 });
Set the threshold as 200, and start loading the image when the visible area is 200 pixels away from the image. (The literal meaning of this sentence The meaning is inconsistent with my understanding. Original text: Setting threshold to 200 causes image to load 200 pixels before it is visible.)
Placeholder image
You can also set a placeholder image and define events to trigger the loading action. At this time, you need to set a URL address for the placeholder image. Transparent, gray and white 1×1 pixel images are already included in the plug-in.
Event triggered loading
The event can be any jQuery event, such as: click and mouseover. You can also use custom events, such as: sporty and foobar. By default, it is in a waiting state until the user scrolls to the position of the picture on the window. In the gray placeholder To prevent the image from loading before it is clicked, you can do this:
$("img").lazyload({
placeholder : "img/grey.gif",
event : "click"
});
Use special effects
When the image is fully loaded, the plug-in uses the show() method to display the image by default. In fact, you can use any special effects you want to process. The following code uses the FadeIn effect. This is the demo page.
$("img").lazyload({
placeholder : "img/grey.gif",
effect : "fadeIn"
});
The image is inside the container
You can use the plug-in on images in scrollable containers, such as DIV elements with scroll bars. All you have to do is define the container as a jQuery object and pass it as a parameter to the initialization method. . This is a horizontal scrolling demo page and a vertical scrolling demo page.
CSS code:
#container { height: 600px;overflow: scroll; }
JavaScript code:
$("img").lazyload({
placeholder : "img/grey.gif ",
container: $("#container")
});
When the images are not arranged in order
When the page is scrolled, Lazy Load will cycle through the loaded images . Check whether the image is within the visible area in the loop. By default, the loop stops when the first image is found that is not in the visible area. Images are considered to be distributed in a fluid manner, and the order of the images in the page and the order in the HTML code The same. But in some layouts, this assumption is not true. However, you can control the loading behavior through the failurelimit option.
$("img").lazyload({
failurelimit : 10
});
Set failurelimit to 10 Let the plug-in find 10 images that are not in the visible area before stopping the search. If you have a cumbersome layout, please set this parameter higher.
Lazy loading of images
An incomplete function of the Lazy Load plug-in. But this can also be used to implement delayed loading of images. The following code implements loading after the page is loaded. 5 seconds after the page is loaded, the images in the specified area will be automatically loaded. This is a delayed loading demonstration page.
$(function() {
$("img: below-the-fold").lazyload({
placeholder : "img/grey.gif",
event : "sporty"
});
});
$(window ).bind("load", function() {
var timeout = setTimeout(function() {$("img").trigger("sporty")}, 5000);
});

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



SpringDataJPA is based on the JPA architecture and interacts with the database through mapping, ORM and transaction management. Its repository provides CRUD operations, and derived queries simplify database access. Additionally, it uses lazy loading to only retrieve data when necessary, thus improving performance.

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Here are some ways to optimize HTML images that are too large: Optimize image file size: Use a compression tool or image editing software. Use media queries: Dynamically resize images based on device. Implement lazy loading: only load the image when it enters the visible area. Use a CDN: Distribute images to multiple servers. Use image placeholder: Display a placeholder image while the image is loading. Use thumbnails: Displays a smaller version of the image and loads the full-size image on click.

Decoding Laravel performance bottlenecks: Optimization techniques fully revealed! Laravel, as a popular PHP framework, provides developers with rich functions and a convenient development experience. However, as the size of the project increases and the number of visits increases, we may face the challenge of performance bottlenecks. This article will delve into Laravel performance optimization techniques to help developers discover and solve potential performance problems. 1. Database query optimization using Eloquent delayed loading When using Eloquent to query the database, avoid

Tips for optimizing Hibernate query performance include: using lazy loading to defer loading of collections and associated objects; using batch processing to combine update, delete, or insert operations; using second-level cache to store frequently queried objects in memory; using HQL outer connections , retrieve entities and their related entities; optimize query parameters to avoid SELECTN+1 query mode; use cursors to retrieve massive data in blocks; use indexes to improve the performance of specific queries.

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

The HibernateORM framework has the following shortcomings: 1. Large memory consumption because it caches query results and entity objects; 2. High complexity, requiring in-depth understanding of the architecture and configuration; 3. Delayed loading delays, leading to unexpected delays; 4. Performance bottlenecks, in May occur when a large number of entities are loaded or updated at the same time; 5. Vendor-specific implementation, resulting in differences between databases.

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:
