Created
December 26, 2011 10:06
-
-
Save terkel/1520842 to your computer and use it in GitHub Desktop.
jQuery Lazy Load plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*! | |
| * jQuery Lazy Load plugin v0.9.2 | |
| * https://gist.github.com/1520842 | |
| * | |
| * Copyright (c) 2012 Takeru Suzuki - http://terkel.jp/ | |
| * Licensed under the MIT license - http://www.opensource.org/licenses/MIT | |
| */ | |
| (function (window, $) { | |
| $.fn.lazyLoad = function (options) { | |
| var opts = $.extend({}, $.fn.lazyLoad.defaults, options); | |
| return this.each(function () { | |
| var $window = $(window), | |
| $this = $(this).css({ opacity: 0 }), | |
| didScroll = false; | |
| $window.bind('scroll', function () { | |
| didScroll = true; | |
| }); | |
| setInterval(function () { | |
| if (didScroll) { | |
| var y = $window.scrollTop(), | |
| h = $window.height(), | |
| offsetTop = $this.offset().top; | |
| if ((y + h) > (offsetTop - opts.threshold)) { | |
| $this.animate({ opacity: 1 }, opts.duration, opts.easing); | |
| } | |
| didScroll = false; | |
| } | |
| }, 200); | |
| $window.trigger('scroll'); | |
| }); | |
| } | |
| $.fn.lazyLoad.defaults = { | |
| threshold: 0, | |
| duration: 400, | |
| easing: 'swing' | |
| }; | |
| })(window, jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*! | |
| * jQuery Lazy Load plugin v0.9.2 | |
| * https://gist.github.com/1520842 | |
| * | |
| * Copyright (c) 2012 Takeru Suzuki - http://terkel.jp/ | |
| * Licensed under the MIT license - http://www.opensource.org/licenses/MIT | |
| */ | |
| (function(c,a){a.fn.lazyLoad=function(d){var e=a.extend({},a.fn.lazyLoad.defaults,d);return this.each(function(){var b=a(c),g=a(this).css({opacity:0}),f=!1;b.bind("scroll",function(){f=!0});setInterval(function(){if(f){var a=b.scrollTop(),c=b.height(),d=g.offset().top;a+c>d-e.threshold&&g.animate({opacity:1},e.duration,e.easing);f=!1}},200);b.trigger("scroll")})};a.fn.lazyLoad.defaults={threshold:0,duration:400,easing:"swing"}})(window,jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment