IE7 中可滚动 Div 中的 JQuery Accordion
我正在尝试构建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我没有 IE7 来测试这个,但我认为主要问题是
overflow:auto
。为你的 HTML 尝试这种风格另一个问题(我猜这只是上面代码中的一个拼写错误,因为你说它在其他浏览器中工作是 contDiv 需要是一个 jQuery 对象:
更新:好的,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 HTMLAnother 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:
Update: Ok, IE does need the
position:relative
to work properly. I updated the HTML above withleft: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.