Genius is nothing but great effort applied. – Awa Kenzo

How To: Use jQuery Lazy Load in Thesis

Maybe you’ve seen the “fade-in” effect of the content and images loading as you scroll down on some popular sites (most notably mashable.com) that effect is called “Lazy Load” and I’ll show you to roll it out in under five minutes.

Before we get started, you have download the jQuery and Placeholder image (right-click “save as”)

jQuery Lazy Load (minified) | Lazyload.gif

Now you have to upload those two files. Upload them to /wp-content/uploads/scripts/

Step 1: Insert the following into custom_functions.php

function lazy_load_html() {
?>
<script src="http://cdn.gregrickaby.com/wp-content/uploads/scripts/jquery.lazyload.mini.js.gzip" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
 if (navigator.platform == "iPad") return;
 $("img").lazyload({
 placeholder : "http://cdn.gregrickaby.com/wp-content/uploads/scripts/lazyload.gif",
 effect : "fadeIn"
 });
});
</script>
<?php }
add_action('thesis_hook_after_html','lazy_load_html');

Step 2 (optional): Turn on the jQuery library in Thesis Options –> Design Options –> JavaScript

Lazy Load Thesis

Why is this optional? Because you may already have the jQuery library running. To check, you should view your source-code and look for something similar to this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

If you see this, then a plug-in has already loaded jQuery and there is no need to load it twice. (this is the reason 99% plug-ins conflict with each other and break)

Step 3: There is no step three. It was that easy. Enjoy!

For more information, check out the official website: Lazy Load Plug-in for jQuery andw00t for one less plug-in you have to install!

Greg Rickaby runs on the Genesis Framework

Genesis Framework

The theme you're viewing is the eleven40 Child Theme, which was built on Genesis.

Genesis empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go. It's that simple - start using Genesis now!

Take advantage of the 6 default layout options, comprehensive SEO settings, rock-solid security, flexible theme options, cool custom widgets, custom design hooks, and a huge selection of child themes ("skins") that make your site look the way you want it to. With automatic theme updates and world-class support included, Genesis is the smart choice for your WordPress website or blog.

Comments

  1. alex says:

    this doesn’t work on IE8 and lower

    do you have a fix for it?

  2. Shubham says:

    Hey, I couldn’t make this work..I am using slidedeck plugin..Is it creating conflicts?

  3. JC says:

    Greg

    How would you utilize this code to get the smooth scrolling back to top??
    http://snipplr.com/view/12510/smooth-scrolling-with-jquery-and-internal-page-links/

  4. David Alexander says:

    Hi Greg, I found the solution and thought he only right thing would be to put it on here. I edited 3 lines of the code which is added to custom_functions


    jQuery(document).ready(function($){
    if (navigator.platform == "iPad") return;
    $("img").lazyload({

    to

    jQuery(document).ready(function($){
    if (navigator.platform == "iPad") return;
    jQuery("#content,#footer").find("img").lazyload({

    This tells the lazy load only to effect the content and footer divs, and ignore sidebar, header and anything else not specified.

    Thanks

  5. David Alexander says:

    I love this solution. Worked on all the sites I tried it on apart from I have one question.

    Is there a way to exclude the sidebar from this?

    If you see http://grievousbodilycharm.com/ the sidebar images dont load until you have gone to the bottom and then back to the top, I guess because the sidebar is technically after the content area? Any ideas?

    Thanks

  6. JC says:

    Greg,

    thanks a lot. I just redesigned my site about a week ago and just added this lil snippet to the mix. It’s a great addition!

    JC

  7. Meedo Taha says:

    Just what I was looking for! Thanks so much. I’ve been trying to do this for the past week and now it works!

    On a related note, I’ve bee trying to implement javascript or jquery tooltips on my site (I use tooltips extensively to define words that may be unfamiliar to the readers of my blog, but the default tooltips are too slow and generic for them to be noticed by most my readers).

    Any thoughts on how to achieve that? Thanks.

  8. Lee Hughes says:

    Love it!

    Would like to see more stuff like this via the thesis ninjas :)

Trackbacks

  1. [...] posts: How to Use jQuery Lazy Load in Thesis 1.7 Thesis 1.8 Header Image How to Create a Sub-Loop in [...]

  2. [...] How to Use jQuery Lazy Load in Thesis 1.7 [...]

  3. [...] How To: Use jQuery Lazy Load in Thesis 1.7 | Greg Rickaby dESIGN If you enjoyed this article please consider sharing [...]

Speak Your Mind

*