What is the simplest jQuery way to have a 'position:fixed' (always at top) div?

后端 未结 6 577
醉梦人生
醉梦人生 2020-11-28 20:39

I\'m relatively new to jQuery, but so far what I\'ve seen I like. What I want is for a div (or any element) to be across the top of the page as if \"position: fixed\" worked

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 21:02

    For those browsers that do support "position: fixed" you can simply use javascript (jQuery) to change the position to "fixed" when scrolling. This eliminates the jumpiness when scrolling with the $(window).scroll(function()) solutions listed here.

    Ben Nadel demonstrates this in his tutorial: Creating A Sometimes-Fixed-Position Element With jQuery

提交回复
热议问题