Permalink
Browse files

Add support for James Padolseys scrollstop event.

  • Loading branch information...
tuupola committed Nov 26, 2011
1 parent e400e4a commit d61b5a0a009d23e17badda1cbd6ded316625fad7
Showing with 78 additions and 5 deletions.
  1. +1 −0 README.textile
  2. +2 −1 enabled_gazillion.html
  3. +3 −3 jquery.lazyload.js
  4. +1 −1 jquery.lazyload.min.js
  5. +71 −0 jquery.scrollstop.js
View
@@ -4,6 +4,7 @@ h4. 1.6.0
* Rename original attribute to data-original to be HTML5 friendly.
* Remove all code regarding placeholder and automatically removing src attribute. It does not work with modern browsers. Must use data-original attribute instead.
+* Add support for James Padolseys "scrollstop event":http://james.padolsey.com/javascript/special-scroll-events-for-jquery/. Use when you have hundreds of images.
h4. 1.5.0
View
@@ -79,11 +79,12 @@ <h2>Plugin enabled with gazillion images</h2>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript" charset="utf-8"></script>
+ <script src="jquery.scrollstop.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.lazyload.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
$("img").lazyload({
- effect: "fadeIn"
+ event: "scrollstop"
});
});
</script>
View
@@ -29,8 +29,8 @@
/* Fire one scroll event per scroll. Not one scroll event per image. */
var elements = this;
- if ("scroll" == settings.event) {
- $(settings.container).bind("scroll", function(event) {
+ if (0 == settings.event.indexOf("scroll")) {
+ $(settings.container).bind(settings.event, function(event) {
var counter = 0;
elements.each(function() {
if ($.abovethetop(this, settings) ||
@@ -76,7 +76,7 @@
/* When wanted event is triggered load original image */
/* by triggering appear. */
- if ("scroll" != settings.event) {
+ if (0 != settings.event.indexOf("scroll")) {
$(self).bind(settings.event, function(event) {
if (!self.loaded) {
$(self).trigger("appear");
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,71 @@
+/* http://james.padolsey.com/javascript/special-scroll-events-for-jquery/ */
+
+(function(){
+
+ var special = jQuery.event.special,
+ uid1 = 'D' + (+new Date()),
+ uid2 = 'D' + (+new Date() + 1);
+
+ special.scrollstart = {
+ setup: function() {
+
+ var timer,
+ handler = function(evt) {
+
+ var _self = this,
+ _args = arguments;
+
+ if (timer) {
+ clearTimeout(timer);
+ } else {
+ evt.type = 'scrollstart';
+ jQuery.event.handle.apply(_self, _args);
+ }
+
+ timer = setTimeout( function(){
+ timer = null;
+ }, special.scrollstop.latency);
+
+ };
+
+ jQuery(this).bind('scroll', handler).data(uid1, handler);
+
+ },
+ teardown: function(){
+ jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
+ }
+ };
+
+ special.scrollstop = {
+ latency: 300,
+ setup: function() {
+
+ var timer,
+ handler = function(evt) {
+
+ var _self = this,
+ _args = arguments;
+
+ if (timer) {
+ clearTimeout(timer);
+ }
+
+ timer = setTimeout( function(){
+
+ timer = null;
+ evt.type = 'scrollstop';
+ jQuery.event.handle.apply(_self, _args);
+
+ }, special.scrollstop.latency);
+
+ };
+
+ jQuery(this).bind('scroll', handler).data(uid2, handler);
+
+ },
+ teardown: function() {
+ jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
+ }
+ };
+
+})();

0 comments on commit d61b5a0

Please sign in to comment.