同时滚动多个div [英] Scroll multiple div at the same time
问题描述
我试着同时滚动多个 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());
});
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());
});
这篇关于同时滚动多个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!