position:fixed when left/top/right/bottom aren't specified - desired results in FF/IE, but not in Safari

后端 未结 3 2093
梦毁少年i
梦毁少年i 2020-12-01 10:31

Sorry to have to ask yet another position:fixed related question, but reading through various other questions and forum threads hasn\'t helped me with this one.

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 11:09

    I had the same requirement, to position an element fixed at it's natural (default) static position with relation to the viewport. I ended up using this simple jQuery function.

    function SetFixedPositioning(element) {
        var currentOffset = $(element).offset();
        $(element).css("position", "fixed");
        $(element).offset(currentOffset);           
    }
    

    Use it like this:

    SetFixedPosition($("#element-to-position"));
    

    My use case was a second level navigation menu that flowed into the document, then was fixed at that position.

提交回复
热议问题