开发者 | omac |
---|---|
更新时间 | 2019年3月2日 00:25 |
捐献地址: | 去捐款 |
PHP版本: | 2.8.0 及以上 |
WordPress版本: | 5.1.0 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
/wp-content/plugins/wp-lazy-loaded-images
directory, or install the plugin through the WordPress plugins screen directly.As of 2.0.0, Images now load as a transparent gif, which should remove the need to add custom image colors, and make it work in more situations automatically.
With the new lazy load library, a few helper CSS classes are included by default. The full documentation can be found here, but the gist of it [pulled from the github repo] is as follows: / fade image in after load / .lazyload, .lazyloading { opacity: 0; } .lazyloaded { opacity: 1; transition: opacity 300ms; }
As of 1.4.0, the plugin also adds support for a noscript
fallback so the images will appear in browsers that might have Javascript disabled.
To take full advantage of this, the plugin provides a fully automatic solution using the following filter to your functions.php
, add_filter( 'lazy_load_enable_fallback', '__return_true' )
. This method will automatically handle all of the below instructions. If you're developing a custom theme you might want to include the following instructions manually, in that case you can use add_filter( 'lazy_load_enable_noscript', '__return_true' )
to only add the <noscript>
tags and leave the styles, javascript, and body classes untouched.
NOTE: This fallback only works on the images that are replaced inside the body of the pages, and those generated by using the_post_thumbnail
.
Add the following CSS:
.no-js .lazyload.lazy-fallback {
display: none;
}
Add the following JS inside as close to the opening body
tag as possible:
var body = document.getElementsByTagName('body')[0];
if (body != undefined) {
body.setAttribute('class', body.getAttribute('class').replace('no-js', ''));
}
And append this snippet to your functions.php:
add_filter( 'body_class', function ( $classes, $class ) {
if ( ! in_array( 'no-js', $classes ) ) {
$classes[] = 'no-js';
}
return $classes;
}, 10, 2 );
noscript
fallback using lazy_load_enable_fallback
filter. Disabled by default for compatibility. See FAQ for instructions.the_content
parser to a DOM parser to be a bit more accurate when replacing images, and better support for attributes (alt, title, classes)data-no-lazy
on the image you don't want loading inside the post/page content area