提问人:displé nam 提问时间:11/15/2023 更新时间:11/15/2023 访问量:38
jQuery中的生涩滚动动画
Jerky scroll animation in jQuery
问:
我在这个网站上工作 https://staging.sophiepeirano.com/fr/ 不幸的是,滚动在 chrome 上很生涩,但在 firefox 中却没有 如何纠正chrome上的错误?这是前面的JS文件,所以你可以帮我
我试图在第一个元素上使用纯 JS 而不是 jQuery,但没有任何变化
<script>
$=jQuery;
//$(window).on('scroll', function(e) {
window.addEventListener('scroll', function (e) {
var ScrollVal = $(document).scrollTop();
if(ScrollVal < window.innerWidth) {
//$('[data-scroll-id=content]').css({'left': '-'+ScrollVal+"px", 'top': ''+ScrollVal+"px"});
//$('[data-scroll-id=content]').css('top', ''+ScrollVal+"px");
var dsid = document.querySelector("[data-scroll-id=content]");
dsid.style.left = '-'+ScrollVal+"px";
dsid.style.top = ''+ScrollVal+"px";
}
else if(ScrollVal >= window.innerWidth && ScrollVal < window.innerWidth*2+$('[data-scroll-id=presentation] > *').height()) {
relativeScroll = ScrollVal-window.innerWidth;
$('[data-scroll-id=content]').css('left', '-'+window.innerWidth+"px");
$('[data-scroll-id=content]').css('top', ''+ScrollVal+"px");
$('[data-scroll-id=presentation] > *').css('marginTop', '-'+(relativeScroll/2)+"px")
}
else if (ScrollVal >= window.innerWidth*2+$('[data-scroll-id=presentation] > *').height() && ScrollVal < (window.innerWidth*3+$('[data-scroll-id=presentation] > *').height())) {
console.log('the 3')
relScroll = ScrollVal-(window.innerWidth*2+$('[data-scroll-id=presentation] > *').height())
$('[data-scroll-id=content]').css('top', ''+ScrollVal+"px");
$('[data-scroll-id=content]').css('left', '-'+window.innerWidth-relScroll+"px");
}
else if (ScrollVal >= (window.innerWidth*3+$('[data-scroll-id=presentation] > *').height()) && ScrollVal < (window.innerWidth*3+$('[data-scroll-id=presentation] > *').height()+$('[data-scroll-id=services] > *').height())) {
console.log('the 4')
relScroll = ScrollVal-(window.innerWidth*2+$('[data-scroll-id=presentation] > *').height()+window.innerWidth)
$('[data-scroll-id=content]').css('top', ''+ScrollVal+"px");
$('[data-scroll-id=content]').css('left', '-'+window.innerWidth*2+"px");
$('[data-scroll-id=services] > *').css('marginTop', '-'+(relScroll/2)+"px")
}
})
</script>
答: 暂无答案
评论
$(document)
$('[data-scroll-id=content]')