所以现在我已经在Javascript中创建了一个onload函数....但是当我发现我不能在我正在使用的应用程序中使用任何onLoad javascript函数时已经很晚了:(
<script type="text/javascript">
var sticky = document.querySelector('.sticky');
var origOffsetY = sticky.offsetTop;
function onScroll(e) {
window.scrollY >= origOffsetY ? sticky.classList.add('fixed') :
sticky.classList.remove('fixed');
}
document.addEventListener('scroll', onScroll);
</script>
有人建议我使用BindListeners,但我不知道它是如何工作的?有帮助吗?我也不能使用jQuery ....
答案 0 :(得分:0)
var sticky = document.querySelector('.sticky');
var origOffsetY = sticky.offsetTop;
function onScroll(e) {
window.scrollY >= origOffsetY ? sticky.classList.add('fixed'):sticky.classList.remove('fixed');
}
(function() {
document.addEventListener('scroll', onScroll);
})();
你正在使用jQuery吗?