国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Web Front-end JS Tutorial Lazy Load jQuery plug-in for lazy loading of images_jquery

Lazy Load jQuery plug-in for lazy loading of images_jquery

May 16, 2016 pm 06:35 PM
lazy load

How to use?
Lazy Load relies on jQuery. Please add the following code to the page head area:
Copy the code The code is as follows:




And add the following statement to your execution code:
Copy code The code is as follows:
?
$("http://www.appelsiini.net/projects/lazyload/img").lazyload() ;

This will cause images under the id="http://www.appelsiini.net/projects/lazyload/img" area to be lazy loaded.
Set sensitivity
The plug-in provides the threshold option, which can control the loading of images by setting the threshold value (the distance from the trigger loading point to the image). The default value is 0 (loading when the image boundary is reached).
Copy code The code is as follows:
?
$("http://www.appelsiini.net/projects/lazyload/img").lazyload( { threshold : 200 });

Set the threshold to 200, and start loading the image when the visible area is 200 pixels away from the image. (The literal meaning of this sentence is the same as mine. Inconsistent 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. In this case, you need Set a URL for the placeholder image. Transparent, gray and white 1x1 pixel images are already included in the plugin.
Copy code The code is as follows:

$("img").lazyload({ placeholder : "img/grey.gif" });

event The trigger loading
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 window. Location. To prevent the gray placeholder image from loading before it is clicked, you can do this:
Copy the code The code is as follows:

$("img").lazyload({
placeholder : "img/grey.gif",
event : "click"
});

Use special effects
When the image is fully loaded, the plug-in uses the show() method by default to display the image. In fact, you can use any special effects you want to process. Below The code uses the FadeIn effect. This is the demo page.
Copy the code The code is as follows:

$ ("img").lazyload({
placeholder : "img/grey.gif",
effect : "fadeIn"
});

Picture in 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 It is a horizontal scrolling demo page and a vertical scrolling demo page.
CSS code:
Copy code The code is as follows:

#container {
height: 600px;
overflow: scroll;
}

JavaScript code:
Copy code The code is as follows:

$("img").lazyload({
placeholder : "img/grey.gif",
container: $("#container")
});

When the images are not arranged in order
When scrolling the page, Lazy Load will loop through the loaded images. In the loop, it will check whether the image is within the visible area. By default, the first image will be found The loop stops when there is an image 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 is the same as the order in the HTML code. However, in some layouts, this assumption is not true. However, you can pass failurelimit options to control loading behavior.
Copy code The code is as follows:
?
$("img") .lazyload({
failurelimit : 10
});

Set the failurelimit to 10 so that the plug-in will stop searching only after finding 10 images that are not in the visible area. If you have a naughty layout, please set this parameter higher.
Lazy loading of images
An incomplete function of the Lazy Load plug-in, but it can also be used to implement lazy loading of images. The following code implements the page loading completion 5 seconds after the page is loaded, the images in the specified area will be loaded automatically. This is a delayed loading demo page.
Copy code The code is as follows:

$(function() {
$("img:below-the-fold").lazyload({
placeholder: "img/grey .gif",
event : "sporty"
});
});
$(window).bind("load", function() {
var timeout = setTimeout( function() {$("img").trigger("sporty")}, 5000);
});

Download plug-in
Latest version: Source code, Compressed code, Packed code
Known issues
Due to webkit bug #6656, Lazy Load does not work in Safari and Chrome. It will immediately load all the images you want and don't want to be loaded.
It seems that jQuery 1.3.x makes the plug-in invalid in IE. . All images will be loaded in the background even if they should not be loaded. The author is working on solving this problem, and in the meantime can only use the plugin in jQuery 1.2.6.
Also, if you use Mint , please add the mint tag to the head of the page. If you add the mint tag to the end of the page, it will interfere with the Lazy Load plug-in. This is a fairly rare problem. If anyone finds a solution, please contact the author.
Statement of this Website
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Java vs. JavaScript: Clearing Up the Confusion Java vs. JavaScript: Clearing Up the Confusion Jun 20, 2025 am 12:27 AM

Java and JavaScript are different programming languages, each suitable for different application scenarios. Java is used for large enterprise and mobile application development, while JavaScript is mainly used for web page development.

Javascript Comments: short explanation Javascript Comments: short explanation Jun 19, 2025 am 12:40 AM

JavaScriptcommentsareessentialformaintaining,reading,andguidingcodeexecution.1)Single-linecommentsareusedforquickexplanations.2)Multi-linecommentsexplaincomplexlogicorprovidedetaileddocumentation.3)Inlinecommentsclarifyspecificpartsofcode.Bestpractic

How to work with dates and times in js? How to work with dates and times in js? Jul 01, 2025 am 01:27 AM

The following points should be noted when processing dates and time in JavaScript: 1. There are many ways to create Date objects. It is recommended to use ISO format strings to ensure compatibility; 2. Get and set time information can be obtained and set methods, and note that the month starts from 0; 3. Manually formatting dates requires strings, and third-party libraries can also be used; 4. It is recommended to use libraries that support time zones, such as Luxon. Mastering these key points can effectively avoid common mistakes.

JavaScript vs. Java: A Comprehensive Comparison for Developers JavaScript vs. Java: A Comprehensive Comparison for Developers Jun 20, 2025 am 12:21 AM

JavaScriptispreferredforwebdevelopment,whileJavaisbetterforlarge-scalebackendsystemsandAndroidapps.1)JavaScriptexcelsincreatinginteractivewebexperienceswithitsdynamicnatureandDOMmanipulation.2)Javaoffersstrongtypingandobject-orientedfeatures,idealfor

Why should you place  tags at the bottom of the ? Why should you place tags at the bottom of the ? Jul 02, 2025 am 01:22 AM

PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl

JavaScript: Exploring Data Types for Efficient Coding JavaScript: Exploring Data Types for Efficient Coding Jun 20, 2025 am 12:46 AM

JavaScripthassevenfundamentaldatatypes:number,string,boolean,undefined,null,object,andsymbol.1)Numbersuseadouble-precisionformat,usefulforwidevaluerangesbutbecautiouswithfloating-pointarithmetic.2)Stringsareimmutable,useefficientconcatenationmethodsf

What is event bubbling and capturing in the DOM? What is event bubbling and capturing in the DOM? Jul 02, 2025 am 01:19 AM

Event capture and bubble are two stages of event propagation in DOM. Capture is from the top layer to the target element, and bubble is from the target element to the top layer. 1. Event capture is implemented by setting the useCapture parameter of addEventListener to true; 2. Event bubble is the default behavior, useCapture is set to false or omitted; 3. Event propagation can be used to prevent event propagation; 4. Event bubbling supports event delegation to improve dynamic content processing efficiency; 5. Capture can be used to intercept events in advance, such as logging or error processing. Understanding these two phases helps to accurately control the timing and how JavaScript responds to user operations.

What's the Difference Between Java and JavaScript? What's the Difference Between Java and JavaScript? Jun 17, 2025 am 09:17 AM

Java and JavaScript are different programming languages. 1.Java is a statically typed and compiled language, suitable for enterprise applications and large systems. 2. JavaScript is a dynamic type and interpreted language, mainly used for web interaction and front-end development.

See all articles