jQuery SimplyScroll 插件在某些缩放级别上中断
您实际上可以在 SimplyScroll 演示页面上看到此效果:使用 Safari、Chrome 或 Firefox,然后缩小以至于页面元素非常小,并且滚动条停止移动。
我已经进行了测试和实验,看来scrollLeft 值在setInterval 循环内递增,但它不会“粘住”,而只是停留在前一个滚动值。更奇怪的是,从控制台手动更改滚动值效果很好。
这是相关的片段:
self.interval = setInterval(function() {
// snip
// increment by 1 pixel
self.$clip[0].scrollLeft += self.o.speed;
// scrollLeft value is unchanged
// snip
},self.intervalDelay); // usually set to 41
我尝试用 requestAnimationFrame 替换 setInterval,并且还大幅降低速度,但没有结果;我很困惑。关于为什么缩放级别会影响计时器回调内滚动的能力有什么想法吗?
You can actually see this effect on the SimplyScroll demo page: use Safari, Chrome or Firefox, and zoom out to the point that page elements are very small, and the scroller stops moving.
I've tested and experimented, and it appears that the scrollLeft value is being incremented within a setInterval loop, but it doesn't "stick", and just stays at the previous scroll value instead. Even more strangely, altering the scroll value manually from the console works just fine.
Here is the relevant snippet:
self.interval = setInterval(function() {
// snip
// increment by 1 pixel
self.$clip[0].scrollLeft += self.o.speed;
// scrollLeft value is unchanged
// snip
},self.intervalDelay); // usually set to 41
I've tried replacing setInterval with requestAnimationFrame, and also drastically turning down the speed, and no results; I'm stumped. Any ideas on why zoom level is affecting the ability to scroll within a timer callback?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想通了:看起来它与缩小时构成“像素”的内容有关;单个像素的变化计算为小于一个像素,这不会导致任何变化。我计划向开发人员提交错误报告;目前,我已经实施了以下
hack解决方法:I figured it out: it looks like it has do with what constitutes a "pixel" when zoomed out; a single-pixel change evaluates to being less than one pixel, which leads to no change. I plan to file a bug report with the developer; for now, I've implemented the following
hackworkaround:第 1 步:在下面添加函数
第 2 步:在 init 函数上调用它
step 1: Add function below
Step 2: call it on init function