cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.87k stars 3.8k forks source link

Defining several indicators #1196

Closed epigeyre closed 7 years ago

epigeyre commented 7 years ago

I'm trying to understand how parallax works with iscroll5. From what I understand, I can define a container as an indicator to alter scroll speed. However what I need to do is to apply a speed ratio to several elements at the same time.

Let's take the example below, how would I proceed to change the speedratioX of all h2 elements at once without modyfing the HTML?

<div class="iscroll__wrapper">
  <ul>
    <li>
      <figure><img src="https://lorempixel.com/900/200"></figure>
      <h2 class="title">Title 1</h2>
    </li>
    <li>
      <figure><img src="https://lorempixel.com/900/200"></figure>
      <h2 class="title">Title 1</h2>
    </li>
    <li>
      <figure><img src="https://lorempixel.com/900/200"></figure>
      <h2 class="title">Title 1</h2>
    </li>
  </ul>
</div>

Here is a jsfiddle of the code.

epigeyre commented 7 years ago

Ok so I've found a solution, I don't know about performance issues but from what I've tried I didn't notice any. I'll post my solution here if someone needs it. It's all based on the fact that I've noticed that I can pass an array of indicators, so I'm just using a for loop to generate this array.

Here is the jsfiddle with the answer.