Sticky '_calc' is not an available method for this element

时间:2016-04-04 17:31:10

标签: javascript jquery zurb-foundation sticky zurb-foundation-6

I'm trying to invoke the recalculation of the sticky header when using Foundation 6. However everything i attempt returns

We're sorry, '_calc' is not an available method for this element

Here's the declaration of the sticky element:

<div id="sticky-container" data-sticky-container>
    <div id="sticky" data-sticky data-margin-top="0" data-top-anchor="the-table" 
                     data-btm-anchor="footer:bottom" style="width: 100%">

I've tried:

$('.sticky:visible').foundation('_calc', true);
$('#sticky-container').foundation('_calc', true);
$('#sticky').foundation('_calc', true);

All 3 of these usages returns the _calc is not available.

1 个答案:

答案 0 :(得分:1)

我认为问题是您在使用$(document).foundation();致电.foundation之前未直接致电_calc。在我的测试中,如果在调用$('#sticky').foundation('_calc', true);之前调用$(document).foundation();,我就能够复制错误。问题源于这样一个事实:当你打电话给$('#sticky').foundation('_calc', true);

时,粘性元素还没有被初始化
  1. Fiddle之前调用$(document).foundation();

  2. Fiddle 之后调用$(document).foundation();

  3. 我很确定以上是原因。如果没有,请告诉我。