我正在尝试让滚动跟随 ScrollToFixed.js
这是我的观点:
<ul id="summary1" class="summary">
<li class="caption">Summary 1</li>
<li class="contents">
<p>There are three floating summaries on the right of this page. They are anchored to their respective sections.</p>
<p>Once a summary reaches the bottom of the header above, it will stop there until the next section summary arrives. Then, it will continue up the page.</p>
<p>The last summary will get pushed up the page by the footer once it undocks to reveal the content below it.</p>
</li>
</ul>
<ul id="summary3" class="summary">
<li class="caption">Summary 3</li>
<li class="contents">
<p>There are three floating summaries on the right of this page. They are anchored to their respective sections.</p>
<p>Once a summary reaches the bottom of the header above, it will stop there until the next section summary arrives. Then, it will continue up the page.</p>
<p>The last summary will get pushed up the page by the footer once it undocks to reveal the content below it.</p>
</li>
</ul>
这是 JavaScript:
var summaries = $('.summary');
summaries.each(function(i) {
var summary = $(summaries[i]);
var next = summaries[i + 1];
summary.scrollToFixed({
marginTop: $('.header').outerHeight(true) + 10,
limit: function() {
var limit = 0;
if (next) {
limit = $(next).offset().top - $(this).outerHeight(true) - 10;
} else {
limit = $('.footer').offset().top - $(this).outerHeight(true) - 10;
}
return limit;
},
zIndex: 999
});
});
如果数字是连续的,则运行成功。但如果没有,那就根本不起作用。我知道错误在 var next = summaries[i + 1];
然后我将其替换为 var next = summaries<?php echo $data['id_post']?>;
但它仍然不起作用。
摘要id中的数字1和3是我的id_post。有谁知道如何用 id_post 更改 var next ?
非常感谢您的回答...
最佳答案
如果我理解正确,你可以这样做:
var summary = $(this);
var next = summary.next('.summary');
尝试一下,如果有帮助请告诉我。
关于Javascript - ScrollToFixed 动态 div id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27619015/