Created
July 23, 2017 03:00
-
-
Save nyawach/f9bbb0fa2e7ed15ac43cecb11a319ea7 to your computer and use it in GitHub Desktop.
背景固定(RAF/onScroll両方)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setupFixedBg() { | |
const $fixed = $('.js-fixed-bg'); | |
const $wrapper = isSP() ? $(window) : $('.wrapper'); | |
let _tmpTop = $wrapper.scrollTop(); | |
(function _update() { | |
const top = $wrapper.scrollTop(); | |
if(top !== _tmpTop) { | |
$fixed.css('transform', `translateY(${top}px)`); | |
} | |
_tmpTop = top; | |
requestAnimationFrame(_update); | |
})(); | |
// $wrapper.on('scroll', () => { | |
// const top = $wrapper.scrollTop(); | |
// if(top !== _tmpTop) { | |
// $fixed.css('transform', `translateY(${top}px)`); | |
// } | |
// _tmpTop = top; | |
// }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment