简体   繁体   English

滚动没有Javascript的可滚动DIV?

[英]Scrolling a scrollable DIV without Javascript?

I basically have a fixed width DIV with an unordered list inside that overflows to the right of the DIV when the list is too large. 我基本上有一个固定宽度的DIV,里面有一个无序列表,当列表太大时,它会溢出到DIV的右侧。 It basically looks like this: 基本上看起来像这样:

http://i.imgur.com/Tr36X.jpg http://i.imgur.com/Tr36X.jpg

Each list item (basically a 60x60 image) is clickable and it leads to a page with the same DIV element and same list items, except one is highlighted a different colour to show it's the current image. 每个列表项(基本上是60x60的图像)都是可单击的,它会导致页面具有相同的DIV元素和相同的列表项,只是高亮显示了不同的颜色以表示它是当前图像。 What I'm trying to do is get the one that's currently selected (it has a class="active" attribute) to show in the middle of the scrolling DIV, like so: 我想做的是让当前选择的对象(它具有class="active"属性)显示在滚动DIV的中间,如下所示:

http://i.imgur.com/YtF1y.jpg http://i.imgur.com/YtF1y.jpg

The only way I can think of doing it would be to have a Javascript file included on the page to find what list item has the class="active" attribute, and then scroll along to it using Javascript. 我能想到的唯一方法是在页面上包含一个Javascript文件,以查找具有class="active"属性的列表项,然后使用Javascript滚动至该列表项。 Problem with this is, it won't initially be scrolled to the correct position when the page loads, the user will see it "jump" into position when the Javascript loads and gets executed. 问题是,页面加载时最初不会滚动到正确的位置,用户会在加载并执行Javascript时看到它“跳转”到适当的位置。

Is there a way to do what I want without Javascript? 没有Java,有什么方法可以做我想做的事吗? I don't mind a little bit of markup and CSS hackery if need be. 如果需要的话,我不介意标记和CSS骇客。

Thanks! 谢谢!

I doubt that this can be solved only with CSS and HTML. 我怀疑只有CSS和HTML才能解决此问题。 Unless you use some other language (like PHP) that can generate you an HTML with changed order of DIVs. 除非您使用其他语言(例如PHP),它们可以为您生成具有更改的DIV顺序的HTML。

But, I can solve your Javascript "jumping" problem. 但是,我可以解决您的Javascript“跳跃”问题。

  1. You initially show your DIVs with css style="display:none;" 您最初使用css style =“ display:none;”显示 DIV
  2. Do the scrolling with JavaScript (and other stuff like changing order of DIVs if needed). 使用JavaScript进行滚动(如果需要,还可以进行其他操作,例如更改DIV的顺序)。
  3. Set css style="display:block;" 设置css style =“ display:block;”

ie items will show up on the screen already scrolled. 即项目将显示在已经滚动的屏幕上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM