


Download the revised version of Jquery.LazyLoad.js to implement image lazy loading plug-in_jquery
The version downloaded from the Internet has more or less bugs, especially the flashing of pictures in IE6 and IE7 after loading is a big problem. I searched online for a long time and found no relevant solution. If there is no solution, we have to use our DIY spirit to solve it by ourselves, analyze the bugs, and sort out the ideas. Combined with the method I used to create pop-up window effects some time ago, I solved the compatibility problem of Jquery.LazyLoad.js. Now I will give you the ideas. and methods to share with you.
The solution is roughly two points. One is to start with the filter parameters of LazyLoad itself. It is found that there is a parameter that can be used in IE6 and IE7, which is show, then use this special effect in IE6 and IE7; Second, non-IE core browsers such as IE8 and above (including IE8), FireFox, and Chrome all support the fadeIn effect, so this cool special effect can be used in these versions of browsers.
After the idea came out, I thought of a solution:
1. First, use JQ to determine the browser type and version. If it is a browser below IE8, use effect= show, otherwise use effect=fadeIn. The function to determine the browser version is as follows:
function checkbrowse() {
var ua = navigator.userAgent.toLowerCase();
var is = (ua.match(/b(chrome|opera|safari|msie|firefox)b/) || ['', 'mozilla'])[1];
var r = '(?:' is '|version)[\/: ]([\d.] )';
var v = (ua.match(new RegExp(r)) || [])[1];
jQuery.browser.is = is;
jQuery.browser.ver = v;
return {
'is': jQuery.browser.is,
'ver': jQuery.browser.ver
}
}
I added the above code to the JQ package For future use, the path is http://demo.jb51.net/js/2011/lazyload/Js/lazyload/jquery.js.
2. Modify the Jquery.LazyLoad.js function to display different filter effects according to the browser version:
var public = checkbrowse();
var showeffect = "";
if ((public['is'] == 'msie' && public['ver'] < 8.0)) {
showeffect = "show"
} else {
showeffect = "fadeIn"
}
jQuery(document).ready(function( $) {
$("img").lazyload({
placeholder: "http://demo.jb51.net/js/2011/lazyload/Js/lazyload/grey.gif",
effect: showeffect,
failurelimit: 10
})
});
Instructions for using Jquery.LazyLoad.js:
1. Store the following files in the same directory Below:
jquery.js
jquery.layzload.js
grey.gif
2. Add the following code where special effects are needed:
Jquery.LazyLoad.js plug-in revised version download :
lazyload.rar
Jquery.LazyLoad.js plug-in parameters detailed explanation:
The following explains some parameters of the LazyLoad plug-in for users to make decisions A more relevant effect.
1, use an image to occupy the space in advance
placeholder: "img/grey.gif",
Parameter: placeholder, the value is a certain image path. This image is used to occupy the image to be loaded Position, when the image is loaded, the placeholder image will be hidden
2, what effect to use for loading
effect: "fadeIn",
Parameter: effect (special effect), the value is show( Direct display), fadeIn (fade in), slideDown (drop down), etc. Commonly used fadeIn
3, start loading in advance
threshold: 200,
Parameter: threshold, the value is a number, representing the page height. If set to 200, it means that the scroll bar will start loading the image when it is still 200 meters away from the target position, which can prevent the user from noticing.
4, it will be loaded only when the event is triggered
event: " click",
Parameter: event, the values include click (click), mouseover (mouse over), sporty (sporty), foobar (...). You can realize that the mouse does not move over or the picture starts loading after clicking on it. The latter two The value has not been tested...
5, to achieve the effect for pictures in a certain container
container: $("#container"),
Parameter: container, the value is a certain container. lazyload defaults to pull browsing It takes effect when the scroll bar of a certain DIV is pulled. This parameter allows you to load the pictures in sequence when pulling the scroll bar of a DIV.
6. When the pictures are sorted in a disordered manner. The value is a number. By default, lazyload will not continue loading when it finds the first image that is not in the visible area. However, when the HTML container is confused, images in the visible area may not be loaded. Failurelimit is intended to load N images. Images outside the visible area to avoid this problem.

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

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
