同时滚动多个div [英] Scroll multiple div at the same time

查看:103
本文介绍了同时滚动多个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着同时滚动多个 div 。当我滚动一个 div 时,我想报告所有div的滚动。



我创建div动态。所以我使用函数 document.getElementsByClassName sub-category-container 来获得我所有的元素。我尝试获取当前div的当前滚动以推迟该值。

我无法通过类名来获得它。
您有解决方案吗?

以下是我尝试做的一个例子:
JSFiddle

解决方案

a href =http://api.jquery.com/class-selector/> class selector 。试试这个:

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

DEMO

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

解决方案

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

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

DEMO

这篇关于同时滚动多个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆