Ver Fonte

Offset fix & scroll-down fix

Fixed an issue where the offset was calculated wrong and one where
already shown items where hidden on scroll down
Adam Bouqdib há 11 anos atrás
pai
commit
23c7bc958a
3 ficheiros alterados com 30 adições e 30 exclusões
  1. 15 15
      dist/jquery.smoove.js
  2. 0 0
      dist/jquery.smoove.min.js
  3. 15 15
      src/jquery.smoove.js

+ 15 - 15
dist/jquery.smoove.js

@@ -113,21 +113,21 @@
             
             $(window).on('load', function() {
                 smooveIt();
-            })
-            
-            // throttle scroll handler
-            .scroll(function() {
-                didScroll = true;
+                
+                // throttle scroll handler
+                $(window).scroll(function() {
+                    didScroll = true;
+                });
+                setInterval(function() {
+                    if ( didScroll ) {
+                        didScroll = false;
+                        var scrolltop = $(window).scrollTop(),
+                            direction = (scrolltop < oldScroll) ? direction = 'up' : 'down';
+                        oldScroll = scrolltop;
+                        smooveIt(direction);
+                    }
+                }, 250);
             });
-            setInterval(function() {
-                if ( didScroll ) {
-                    didScroll = false;
-                    var scrolltop = $(window).scrollTop(),
-                        direction = (scrolltop < oldScroll) ? direction = 'up' : 'down';
-                    oldScroll = scrolltop;
-                    smooveIt(direction);
-                }
-            }, 250);
         }
         
         function smooveIt(direction) {
@@ -136,7 +136,7 @@
                     params = $item.params,
                     height = $(window).height(),
                     // if direction isn't set, set offset to 0 to avoid hiding objects that are above the fold
-                    offset = (direction && !$item.css('opacity')) ? params.offset : 0,
+                    offset = (!direction || direction === 'down' && $item.css('opacity') === '1') ? 0 : params.offset,
                     itemtop = $(window).scrollTop() + height - $item.data('top');
                     
                 // offset in %

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/jquery.smoove.min.js


+ 15 - 15
src/jquery.smoove.js

@@ -108,21 +108,21 @@
             
             $(window).on('load', function() {
                 smooveIt();
-            })
-            
-            // throttle scroll handler
-            .scroll(function() {
-                didScroll = true;
+                
+                // throttle scroll handler
+                $(window).scroll(function() {
+                    didScroll = true;
+                });
+                setInterval(function() {
+                    if ( didScroll ) {
+                        didScroll = false;
+                        var scrolltop = $(window).scrollTop(),
+                            direction = (scrolltop < oldScroll) ? direction = 'up' : 'down';
+                        oldScroll = scrolltop;
+                        smooveIt(direction);
+                    }
+                }, 250);
             });
-            setInterval(function() {
-                if ( didScroll ) {
-                    didScroll = false;
-                    var scrolltop = $(window).scrollTop(),
-                        direction = (scrolltop < oldScroll) ? direction = 'up' : 'down';
-                    oldScroll = scrolltop;
-                    smooveIt(direction);
-                }
-            }, 250);
         }
         
         function smooveIt(direction) {
@@ -131,7 +131,7 @@
                     params = $item.params,
                     height = $(window).height(),
                     // if direction isn't set, set offset to 0 to avoid hiding objects that are above the fold
-                    offset = (direction && !$item.css('opacity')) ? params.offset : 0,
+                    offset = (!direction || direction === 'down' && $item.css('opacity') === '1') ? 0 : params.offset,
                     itemtop = $(window).scrollTop() + height - $item.data('top');
                     
                 // offset in %

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff