【问题标题】:Script not working when migrated from jQuery 1.3.2 to 1.6.2从 jQuery 1.3.2 迁移到 1.6.2 时脚本不起作用
【发布时间】:2011-10-14 04:09:41
【问题描述】:

此脚本在 jQuery-1.3.2.min.js 下运行良好,但在 jQuery-1.6.2.min.js 下无法运行。

谁能帮我解决这个问题?

function moveScroller() {
    var a = function () {
            var b = $(window).scrollTop();
            var d = $("#scroller-anchor").offset({
                scroll: false
            }).top;
            var c = $("#scroller");
            if (b > d) {
                c.css({
                    position: "fixed",
                    top: "0px"
                })
            } else {
                if (b <= d) {
                    c.css({
                        position: "relative",
                        top: ""
                    })
                }
            }
        };
    $(window).scroll(a);
    a()
}
$(function () {
    moveScroller();
});

【问题讨论】:

  • 怎么不运行?有什么问题?
  • $(window).scroll(a);a() 是不是假的?不应该是 $(window).scroll(a); ?
  • 偏移量不允许{scroll:false} 那行是什么:if (b c.css({position:"relative",top:""})
  • @Daniel:该代码将a() 设置为窗口滚动事件的事件处理程序,然后单独调用a()——大概是为了初始化。
  • 应该是 ;背后?

标签: jquery compatibility jquery-1.3.2 jquery-1.6


【解决方案1】:

offset()switched to taking coordinates as a parameter with jQuery version 1.4.

变化:

var d = $("#scroller-anchor").offset({scroll:false}).top;

收件人:

var d = $("#scroller-anchor").offset().top;


如果没有看到随之而来的 HTML 和 CSS,我们对其余代码无能为力。

【讨论】:

    【解决方案2】:

    什么是:

    .offset({scroll:false})
    

    偏移函数不带滚动参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多