最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Scroll multiple div at the same time - Stack Overflow

programmeradmin1浏览0评论

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

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

Share Improve this question edited Apr 14, 2014 at 9:35 Chéramy Alexandre asked Apr 4, 2014 at 12:49 Chéramy AlexandreChéramy Alexandre 4643 gold badges9 silver badges25 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 17

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

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

DEMO

Based on your JSFiddle,

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

JSFiddle

发布评论

评论列表(0)

  1. 暂无评论