0

ページスクロールに基づいて要素をスクロールしようとしています。firefoxでは問題なく動作します。

        $(window).scroll(function () {
            var scrollOffset = $(this).scrollTop();
            if (scrollOffset >= ele) {
                $("#UserDataTable thead").css({ "position": "relative" });
                $("#UserDataTable thead").css({ "background-color": "white" });
                $("#UserDataTable thead").css('top', scrollOffset);
            }
            else {
                $("#UserDataTable thead").css({ "position": "" });
                $("#UserDataTable thead").css('top', ele);
            }
        });

// ここの ele は、移動しようとしている thead 要素の初期オフセットです。//

jsfiddle リンクは次のとおりです。

http://jsfiddle.net/UnPAH/3/

しかし、これはIE 8では機能しません。

このコードを機能させるために IE8 で必要な変更を教えてください。

4

1 に答える 1

0


How about that?

$(document).ready(function () {
    var ele = $("table thead").offset().top;
    $(window).scroll(function () {
        var cssProp = null,
            scrollOffset = $(this).scrollTop();
        if (scrollOffset >= ele) {
            cssProp = {
                "background-color": "white",
                'padding-top': scrollOffset
            };
        } else {
            cssProp = {
                'padding-top': ele
            }
        }
        $("table thead tr:eq(0) th").css(cssProp);
        // or $("... td").css(cssProp); what ever elements you're using there
    });
});
于 2013-03-18T14:27:30.257 に答える