简体   繁体   English

免费滚动和视差问题(jQuery Scroll Path + Parallax)

[英]Free scrolling and parallax issue (jQuery Scroll Path + Parallax)

in a project where I need to build something like the famous parallax-powered Mario Kart Wii Experience site, which also comes with horizontal and vertical scroll (if you haven't seen it, here it is: http://www.nintendo.com.au/gamesites/mariokartwii/#home ) 在一个项目中,我需要构建类似著名的视差驱动的Mario Kart Wii Experience网站,该网站还附带水平和垂直滚动条(如果您尚未看到的话,这里是: http://www.nintendo。 com.au/gamesites/mariokartwii/#home

For the scrolling effect, I grabbed the JQuery Scroll Path plugin (website here: http://joelb.me/scrollpath/ ), and it seems to suit my needs concerning the free scrolling. 为了获得滚动效果,我抓住了JQuery Scroll Path插件(网站位于: http : //joelb.me/scrollpath/ ),它似乎满足了我有关自由滚动的需求。

The problem comes when I try to include some plugin to generate the parallax effect. 当我尝试包括一些插件来产生视差效果时,问题就来了。 I tried several plugins (including Stellar.js, jInvertScroll, Parallax.js, Parallax-JS), but none of them seem to work properly. 我尝试了几个插件(包括Stellar.js,jInvertScroll,Parallax.js,Parallax-JS),但似乎都无法正常工作。 I assume that there's some kind of relationship between the custom scroll that comes with the Scroll Path plugin and the need of the parallax plugins of working with the navigator scroll to make the effect work. 我假设Scroll Path插件附带的自定义滚动与使用导航器滚动以使效果起作用所需的视差插件之间存在某种关系。

I searched in Google for some similar situation (ie, implementing Scroll Path with some parallax plugin) but I didn't find anyone in my current situation, and it seems that the Scroll Path plugin isn't maintained anymore. 我在Google中搜索了类似的情况(即,使用一些视差插件实现Scroll Path),但是在当前情况下我找不到任何人,而且似乎不再维护Scroll Path插件。

Any idea for making it work would be appreciated! 任何使它工作的想法将不胜感激!

PS: Sorry for the grammar mistakes, I'm still in process of learning english. PS:抱歉语法错误,我仍在学习英语。

To make 2 plugins working together you should understand how they work. 要使2个插件协同工作,您应该了解它们的工作方式。 Parallax effect is achieved with few layers that are moved with different speed - the closest to you moves fastest, the most distant moves slowest. 视差效果可以通过以不同速度移动的几层来实现-距离您最近的移动最快,距离最远的移动最慢。 Most of the parallax-effect plugins are based on scrollTop calculation - ie layers are moved depending on current scroll offset multiplied by delta-value (which differs depending on layer position). 大多数视差效果插件都是基于scrollTop计算的-即根据当前滚动偏移量乘以delta值(取决于图层位置而有所不同)来移动图层。

In your case you should connect jQuery ScrollPath scroll event to parallax plugin. 在您的情况下,您应该将jQuery ScrollPath滚动事件连接到视差插件。 In ScrollPath you should generate scroll event (that will be handled by parallax plugin) in function scrollToStep (look at row 490 in jquery.scrollpath.js). 在ScrollPath中,您应该在scrollToStep函数中生成滚动事件(将由视差插件处理) (请看jquery.scrollpath.js中的第490行)。 To make calculations simplier you can use 'top' value applied to scrollbar * some delta (you should pick out delta value by yourself). 为了简化计算,您可以将“ top”值应用于滚动条*一些增量(您应该自己选择增量值)。 Then in parallax plugin you should modify event handler that applies parallax effect from scroll / mousewheel to event you generate in ScrollPath plugin. 然后,在视差插件中,您应该修改事件处理程序,以将scroll / mousewheel视差效果应用于在ScrollPath插件中生成的事件。

To connect 2 plugins together you should modify their code which means that you won't be able to easily update these plugins to newer version. 要将2个插件连接在一起,您应该修改它们的代码,这意味着您将无法轻松地将这些插件更新为较新的版本。 You should make comments to all your changes in order to reapply them if plugins will be updated in future. 如果将来要更新插件,则应该对所有更改进行评论,以便重新应用它们。

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

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