javascript - What is the alternative to position:sticky? - Stack Overflow

As per the MDN article on position property, position: sticky is still an experimental API. Also any ve

As per the MDN article on position property, position: sticky is still an experimental API. Also any version Internet explorer doesn't support it yet. So,

Is there any way to achieve the same effect as that of position: sticky with or without javaScript?

I think that it is possible to acheive this effect with position: fixed and without javascript. Because the In This Article section on MDN page behaves exactly like position sticky was applied to it. Even when I disable javaScript it works well. The markup used by MDN I found with inspect element is as,

<div style="width: auto; max-height: none; top: 0px;" id="toc" class="toc toggleable">   ...  
</div>

When I scrolled down the mark up changed to include fixed class on the container div. I don't know how a new class is added without using javascript.

As per the MDN article on position property, position: sticky is still an experimental API. Also any version Internet explorer doesn't support it yet. So,

Is there any way to achieve the same effect as that of position: sticky with or without javaScript?

I think that it is possible to acheive this effect with position: fixed and without javascript. Because the In This Article section on MDN page behaves exactly like position sticky was applied to it. Even when I disable javaScript it works well. The markup used by MDN I found with inspect element is as,

<div style="width: auto; max-height: none; top: 0px;" id="toc" class="toc toggleable">   ...  
</div>

When I scrolled down the mark up changed to include fixed class on the container div. I don't know how a new class is added without using javascript.

Share Improve this question asked Apr 15, 2016 at 5:58 user31782user31782 7,60716 gold badges79 silver badges158 bronze badges 2
  • doesn't work for me with js disabled, are you sure you refreshed the page after disabling it ? – Kaiido Commented Apr 15, 2016 at 6:07
  • @Kaiido I didn't. You are right it doesn't work with js disabled. I think they used js which adds fixed class when the page is scrolled down to touch that div. – user31782 Commented Apr 15, 2016 at 6:09
Add a ment  | 

1 Answer 1

Reset to default 2

use a javascript polyfill like fixed-sticky https://github./filamentgroup/fixed-sticky

on the In This Article section on MDN the fixed class is toggled via javascript, I do not think it's possible to toggle a class on a element on scroll event without resorting to javascript.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745092018a4610747.html

相关推荐

  • javascript - What is the alternative to position:sticky? - Stack Overflow

    As per the MDN article on position property, position: sticky is still an experimental API. Also any ve

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信