2014-02-27 34 views
0

我用这scrollspy插件,我需要重置最小值/最大值时调整窗口大小,因为第一部的高度调整大小,并影响到所有position.top以下部分。什么是最好的方法来做到这一点?如何重置最小值/最大值的jQuery scrollspy在窗口调整

$('section').each(function() { 
    var position = $(this).position(); 
    $(this).scrollspy({ 
     min: position.top - $header.outerHeight(), 
     max: position.top + $(this).outerHeight() - $header.outerHeight(), 
     onEnter: function(element) { 
      $('#main-menu').find('a[href$="'+$(element).attr('id')+'"]').addClass('cur'); 
      /* window.location.hash = 'panel-'+$(element).attr('id'); */ 
     }, 
     onLeave: function(element) { 
      $('#main-menu').find('a[href$="'+$(element).attr('id')+'"]').removeClass('cur'); 
     } 
    }); 
}); 
+0

尝试设置您的部分相对位置 – dreamweiver

+0

是的!作品 - 非常感谢! :) – pixelpalast

回答

0

尝试将节元素的位置设置为相对。

position:relative; 

编码快乐:)

0

我也有类似的问题,但我不能改变我的元素是相对现在的位置,因为它们都是自定义动画,并在绝对位置需要。

这是我的方法。

// Make sure to update Scrollspy once the last resize has fired 
var rtime = new Date(1, 1, 2000, 12,00,00); 
var timeout = false; 
var delta = 200; 
$(window).resize(function() { 
    rtime = new Date(); 
    if (timeout === false) { 
     timeout = true; 
     setTimeout(resizeend, delta); 
    } 
}); 

function resizeend() { 
    if (new Date() - rtime < delta) { 
     setTimeout(resizeend, delta); 
    } else { 
     timeout = false; 
     $(window).unbind("scroll"); 
     // Your Scrollspy function 
    }    
} 
相关问题