简体   繁体   English

jQuery在移动设备上使用skrollr自动滚动?

[英]jQuery to auto-scroll with skrollr on mobile?

I've made a parallax website for iOS using skrollr . 我已经使用skrollr为iOS制作了视差网站。 I'd like to programmatically scroll down to a point on the page. 我想以编程方式向下滚动到页面上的某个点。 I've used jquery scrolling plugins, and they work on desktop, but not mobile. 我使用了jQuery滚动插件,它们在台式机上工作,但不适用于移动设备。 How can I simulate a swipeup or somehow simulate the scrolling to another point with jQuery? 如何使用jQuery模拟滑动或以某种方式模拟滚动到另一点? Thanks! 谢谢!

EDIT: the reason this doesn't work is that on mobile, skrollr doesn't actually scroll due to iOS stopping animation during scroll. 编辑:这行不通的原因是在移动设备上,由于iOS在滚动过程中停止了动画,所以skrollr并未真正滚动。 Instead it listens for touch events and moves the elements. 相反,它侦听触摸事件并移动元素。 That's why a scrollTo plugin won't work. 这就是为什么scrollTo插件不起作用的原因。 (Source: https://github.com/Prinzhorn/skrollr#mobile-support ) (来源: https : //github.com/Prinzhorn/skrollr#mobile-support

Actually I just realize that the skrollr API has this built in! 实际上,我只是意识到skrollr API具有内置功能!

I can just call skrollr.animateTo(400) with skrollr being the variable that was used to initiate skrollr. 我可以调用skrollr.animateTo(400) ,而skrollr是用于启动skrollr的变量。

Hope this helps someone else! 希望这对别人有帮助!

This is more of a FYI. 这更像是仅供参考。

Pros and cons I found when implementing an auto scroll function for mobile with skrollr is this: 我在使用skrollr为手机实现自动滚动功能时发现的优缺点是:

I used two libraries for touch events[jQuery Mobile, hammer.js] I ended up sticking with hammer because I liked the documentation better. 我使用了两个库来处理触摸事件[jQuery Mobile,Hammer.js],由于我更喜欢​​文档,所以最终坚持使用Hammer。

The way I used it on an ipad was simple. 我在ipad上使用它的方式很简单。 I made it if you tap and hold on the right screen, it would auto scroll down until you let go. 如果您点击并按住右侧的屏幕,它将自动向下滚动直到您放开为止。 Vice versa on the left. 反之亦然在左边。

My problem is that it would fail to read the release event and keep scrolling and the user had no way to stop it. 我的问题是它将无法读取释放事件并继续滚动,并且用户无法停止它。

After messing around with it for a bit I decided to change it up. 在弄乱它一段时间后,我决定将其更改。 What I did was place two buttons the user could tap on and it would auto scroll to the next section of my whole skrollr animation. 我所做的是放置两个用户可以点击的按钮,它将自动滚动到整个skrollr动画的下一部分。

Here is an example of my code I wrote. 这是我编写的代码的示例。

var ai = 0;
var positionArray = [0, 1244,3194,15468]
$(function () {
var rightArrow = document.getElementById('right-arrow')
var mcRight = new Hammer(rightArrow);
mcRight.on("tap", function (ev) {
    ai++
    s.animateTo(positionArray[ai])
    //alert(s.getScrollTop())
});


var leftArrow = document.getElementById('left-arrow')
var mcLeft = new Hammer(leftArrow);
mcLeft.on("tap", function (ev) {
    ai--
    s.animateTo(positionArray[ai])

});

})

Hope this helps. 希望这可以帮助。 I wanted it my original way with tap & hold but both plugins had issues reading the taphold release event with the scrolling. 我想要使​​用点击并按住的原始方式,但是两个插件在滚动读取Taphold释放事件时都有问题。

Another issue but super easy to fix by looking at the documentation is no matter how long the length of the section of your animation is, it will take 1 second to get there. 另一个问题,但通过查看文档非常容易解决,无论动画部分的长度有多长,都需要1秒才能到达。 Its nice if it is a small section but if you have a long one it scrub through it very fast. 如果这是一个很小的部分,它很好,但是如果您有一个很长的部分,它会很快擦洗整个部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM