현재 고유 솔루션이 없습니다. Targeting position:sticky elements that are currently in a 'stuck' state을 참조하십시오. 그러나 커피점 솔루션은 고유 한 position: sticky
과 끈적 거림을 구현하는 polyfills 모두에서 작동합니다.
요소에 '끈적'클래스는 끈적 할 추가 : 그들은 '끈적 끈적한'상태에있을 때
.sticky {
position: -webkit-sticky;
position: -moz-sticky;
position: -ms-sticky;
position: -o-sticky;
position: sticky;
top: 0px;
z-index: 1;
}
커피 스크립트는 '갇혀'클래스를 '끈적'요소의 위치를 모니터링하고 추가 :
$ -> new StickyMonitor
class StickyMonitor
SCROLL_ACTION_DELAY: 50
constructor: ->
$(window).scroll @scroll_handler if $('.sticky').length > 0
scroll_handler: =>
@scroll_timer ||= setTimeout(@scroll_handler_throttled, @SCROLL_ACTION_DELAY)
scroll_handler_throttled: =>
@scroll_timer = null
@toggle_stuck_state_for_sticky_elements()
toggle_stuck_state_for_sticky_elements: =>
$('.sticky').each ->
$(this).toggleClass('stuck', this.getBoundingClientRect().top - parseInt($(this).css('top')) <= 1)
참고 :이 코드는 수직으로 고정 된 위치에서만 작동합니다.
그 기사에 최고 등급의 의견이 정확하게 문제를 해결하기 때문에 재미입니다. 그 사람은 그 자리에 자리를 잡았고, 이것은 미디어 질의가 아니라 재산이어야합니다. 그렇게하면 요소가 붙어서 스타일을 변경할 수 있습니다 (우리는 종종 그렇게합니다). 오 잘, 남자는 꿈을 꿀 수있다. –
그래, 나는 그 의견에 주목했다. 그의 제안은 훨씬 더 좋아 보인다. 아직도,'position : sticky'는 크롬이 구현 한 것입니다. 그래서 사용할 수있는 방법을 찾고 있습니다! – AlecRust
해결 방법을 찾으셨습니까? –