Javascript - ScrollToFixed 动态 div id

标签 javascript php jquery

我正在尝试让滚动跟随 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中的数字13是我的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/

相关文章:

c# - JQuery UI 模态表单对话框将数据保存到数据库

Windows 10/IE 11 上的 Javascript HTA ADODB 连接

javascript - 使用 jQuery addClass 转换时出错

php - oscommerce tep_db_perform -- 更新

php - 我想在一个类中读取一个函数

javascript 全局变量 UNSET

javascript - CSS3 Flip Dropdown Menu - 悬停在子菜单上时保留主菜单悬停样式

javascript - 在 Ext JS 4.2 中创建 D3 可折叠树

php - CSRF token 验证失败: PHP POST - SAP

javascript - jquery 查找并替换元素中的关键字