IE7 中可滚动 Div 中的 JQuery Accordion

发布于 2024-10-20 00:04:21 字数 1479 浏览 3 评论 0原文

我正在尝试构建一个 UI,以便将 JQuery Accordion 包含在滚动 div 中。这在 FF 和 IE8 下工作正常,但在 IE7 上完全是嘲讽。具体来说:每当您向上或向下滚动时,整个手风琴都无法正确地上下滑动(其中一部分滚动,但其他部分则不滚动),并且手风琴的某些部分会延伸到 div 之外。单击某些折叠式标头会导致 JQuery 深处出现 JavaScript 错误。

下面是显示此问题的代码(请原谅它的不雅,因为我已从应用程序中的完整 UI 代码中减少了它):

JavaScript 代码:

var contDiv = 'foobar'
var accordionId = 'my_accordion'

contDiv.html(    "<div id='" + accordionId + "'>" +
                    "<h3><a href='#'>First Section</a></h3>" +
                    "<div><p>foo<br>bar<br>baz<br>qux</p></div>" +
                    "<h3><a href='#'>Second Section</a></h3>" +
                    "<div><p>foo<br>bar<br>baz<br>qux</p></div>" +
                    "<h3><a href='#'>Third Section</a></h3>" +
                    "<div><p>foo<br>bar<br>baz<br>qux</p></div>" +
                    "<h3><a href='#'>Fourth Section</a></h3>" +
                    "<div><p>foo<br>bar<br>baz<br>qux</p></div>" +
                  "</div>");

var accordionDiv = $('#' + accordionId);
accordionDiv.accordion({autoHeight: false});

HTML:

<div style="height:100px;overflow:auto;"><div id="foobar"></div></div>

I am attempting to build a UI such that a JQuery Accordion is contained within a scrolling div. This works fine under FF and IE8 but is a complete travesty on IE7. Specifically: whenever you scroll up or down, the entire accordion doesn't slide up and down properly (parts of it scroll, but other parts do not) and parts of the accordion extend outside of the div. Clicking on some of the accordion header results in a javascript error deep in JQuery.

Here is code that exhibits this issue (pardon its inelegance, as I have reduced it down from the full UI code in my application):

JavaScript Code:

var contDiv = 'foobar'
var accordionId = 'my_accordion'

contDiv.html(    "<div id='" + accordionId + "'>" +
                    "<h3><a href='#'>First Section</a></h3>" +
                    "<div><p>foo<br>bar<br>baz<br>qux</p></div>" +
                    "<h3><a href='#'>Second Section</a></h3>" +
                    "<div><p>foo<br>bar<br>baz<br>qux</p></div>" +
                    "<h3><a href='#'>Third Section</a></h3>" +
                    "<div><p>foo<br>bar<br>baz<br>qux</p></div>" +
                    "<h3><a href='#'>Fourth Section</a></h3>" +
                    "<div><p>foo<br>bar<br>baz<br>qux</p></div>" +
                  "</div>");

var accordionDiv = $('#' + accordionId);
accordionDiv.accordion({autoHeight: false});

HTML:

<div style="height:100px;overflow:auto;"><div id="foobar"></div></div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝色星空 2024-10-27 00:04:22

好吧,我没有 IE7 来测试这个,但我认为主要问题是 overflow:auto。为你的 HTML 尝试这种风格

<div style="height:100px; overflow-x:hidden; overflow-y:auto; position:relative; left:0; top: 0;">
 <div id="foobar" style="width:98%"></div>
</div>

另一个问题(我猜这只是上面代码中的一个拼写错误,因为你说它在其他浏览器中工作是 contDiv 需要是一个 jQuery 对象:

var contDiv = $('#foobar');

更新:好的,IE 确实需要 position:relative 才能正常工作。我也用 left:0;top:0; 更新了上面的 HTML,我记得 IE 没有设置这些位置,但我可以'另外,我将 foobar 的宽度设置为 98%,因为 IE 不会调整滚动条的宽度。 rel="nofollow">演示我到目前为止所做的事情。

Ok, I don't have IE7 to test this, but I think the main problem is the overflow:auto. Try this style for your HTML

<div style="height:100px; overflow-x:hidden; overflow-y:auto; position:relative; left:0; top: 0;">
 <div id="foobar" style="width:98%"></div>
</div>

Another problem (and I'm guess it's just a typo in the code above since you said it worked in other browsers is that contDiv need to be a jQuery object:

var contDiv = $('#foobar');

Update: Ok, IE does need the position:relative to work properly. I updated the HTML above with left:0;top:0; as well, I remember IE didn't set those positions, but I can't find the reference. Additionally, I set the width of foobar to 98% because IE does not adjust to the width of the scroll bar. Here is a demo of what I have done so far.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文