jQuery check if browser support position: fixed

后端 未结 7 622
灰色年华
灰色年华 2021-01-04 09:13

How do I check if browser supports position:fixed using jQuery. I assume I have to use $.support I think, but how?

Thank you for your time.

7条回答
  •  礼貌的吻别
    2021-01-04 10:03

    function fixedcheck () {
        var fixedDiv = $('
    ').css('position', 'fixed').appendTo('body'); var pos1 = fixedDiv.offset().top; $(window).scrollTop($(window).scrollTop() + 1); var pos2 = fixedDiv.offset().top; fixedDiv.remove(); return (pos1 != pos2) } /* Usage */ $(document).ready(function () { if (!fixedcheck()) alert('Your browser does not support fixed position!') });

提交回复
热议问题