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.
- 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 thatdiv
. – user31782 Commented Apr 15, 2016 at 6:09
1 Answer
Reset to default 2use 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
评论列表(0条)