瀏覽代碼

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 11 年之前
父節點
當前提交
23c7bc958a
共有 3 個文件被更改,包括 30 次插入30 次删除
  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 %

文件差異過大導致無法顯示
+ 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 %

部分文件因文件數量過多而無法顯示