Chéramy Alexandre
Chéramy Alexandre

Reputation: 464

Scroll multiple div at the same time

I'm trying to scroll multiple div at the same time. when i scroll in one div, i would like to report the scroll in all div.

I create the div dynamically. So i use the function document.getElementsByClassName sub-category-container to get all my elements. And i try to get the current scroll of the current div to defer the value.

I can not get it to work through the class names. Do you have a solution?

Here is an example of what I try to do : JSFiddle

Upvotes: 7

Views: 10796

Answers (2)

Kiran
Kiran

Reputation: 20293

As you are using jQuery already Use class selector. Try this:

var subCatContainer = $(".sub-category-container");
subCatContainer.scroll(function() {
    subCatContainer.scrollLeft($(this).scrollLeft());
});

DEMO

Upvotes: 17

Ugo Stephant
Ugo Stephant

Reputation: 140

Based on your JSFiddle,

$(".sub-category-container").scroll(function() {
    for(var i in subCatContainer)
        $(subCatContainer[i]).scrollLeft($(this).scrollLeft());
});

JSFiddle

Upvotes: 2

Related Questions