【问题标题】:top position on scroll causes lag Safari/IE滚动的顶部位置导致滞后 Safari/IE
【发布时间】:2017-01-19 08:03:37
【问题描述】:

我试图通过使用 position:relative 来固定在顶部位置,

$(document).ready(function() {
    var container = $(".container");

    container.css("overflow-y", "auto");
    container.css("overflow-x", "hidden");

    container.on("scroll", function() {
        $("table", this).css("overflow-x", "hidden");
        $("th", this).css("position", "relative");
        $("th", this).css("z-index", 1);
        $("th", this).css("top", this.scrollTop + "px");
    });
});

问题示例https://jsfiddle.net/hth4Ly7q/2/ 它在 chrome、firefox 中运行良好,但 Safari 和 IE 在滚动时会滞后,也许有人知道如何在 safari 中修复它? 我没有使用绝对/固定位置,因为我的真实表格非常复杂,无法即时计算列宽。

【问题讨论】:

    标签: javascript jquery css internet-explorer safari


    【解决方案1】:

    我在 Edge 和 IE 上试过。看起来没问题。 https://jsfiddle.net/55cynfLg/

    function setTh(){
    var container = $(".container");
    $("table", this).css("overflow-x", "hidden");
    $("th", this).css("z-index", 1);
    container.find("th").each(function(i){
      var td = container.find("tbody tr:eq(0) td:eq("+i+")");
      $(this).css({
         "width": td.width(),
         "left": td.offset().left
      });
    });}
    

    【讨论】:

      【解决方案2】:

      这是我在 Safari 中一直遇到的问题:您无法完全解决它。添加"mousewheel" 事件会有所帮助,但并不能解决问题。

      【讨论】:

        猜你喜欢
        • 2020-01-26
        • 1970-01-01
        • 2011-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多