Javascript-滚动固定在动态div id中

Javascript-滚动固定在动态div id中,javascript,php,jquery,Javascript,Php,Jquery,我正在尝试使用ScrollToFixed.js使scroll跟随 我的看法是: <ul id="summary1" class="summary"> <li class="caption">Summary 1</li> <li class="contents"> <p>There are three float

我正在尝试使用ScrollToFixed.js使scroll跟随

我的看法是:

<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>
如果号码是连续的,它将成功运行。但如果没有,它根本不起作用。我知道错误在var next=总结[I+1];然后我用var next=summaries替换它;但它仍然不起作用

摘要id中的数字1和3是我的id_帖子。有人知道下一步如何用id\u post更改var吗


非常感谢您的回答……

如果我理解正确,您可以这样做:

var summary = $(this);
var next = summary.next('.summary');
试试看,如果有帮助请告诉我。

试试这个


我想,你下一步是没有错的。i是集合中的实际索引,因此它从0开始,然后是1,依此类推。。。让我们来看console.logi;console.logsummary;console.lognext;就在变量nexti之后,我正在尝试这个变量summaries=$'.summary';每个功能的摘要{var summary=$this;var next=summary.next'.summary';但仍然不起作用问题是什么?它是否引发了错误或什么?当我向下滚动时它没有移动…当我向下滚动时应该向下移动。也许你应该将if next更改为if next.length>0。这有帮助吗?如果没有,请在JSFi中发布你的代码ddle,帮助你会更容易。
var summary = $(this);
var next = summary.next('.summary');
var next = $(this).next('.summary');