jquery-ui 手风琴问题:动画冻结 +点击时不显示内容
我正在尝试 jQueryUI 手风琴。我创建了一个测试站点,复制了代码并将其放置到位。效果很好。
然后我尝试将其放入我的网站中。在我的网站上,我有两个菜单。一种是水平的,在顶部。另一个是垂直的,向左。我打算将手风琴应用于垂直菜单。当单击顶部水平菜单中的不同项目时,垂直菜单也会发生变化。
我做的第一件事就是在我的主页上测试它,看看是否与我当前的设计有任何冲突。垂直菜单的代码是这样的:
<!-- leftFrame begin -->
<div id="leftFrame">
<div id="accordion">
<h3><a href="#section1">Section 1</a></h3>
<div>
<p>homepage11111111</p>
</div>
<h3><a href="#section2">Section 2</a></h3>
<div>
<p>homepage22222222</p>
</div>
<h3><a href="#section3">Section 3</a></h3>
<div>
<p>homepage33333333</p>
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
<a href="#othercontent">Link to other content</a>
</div>
</div>
</div> <!-- leftFrame end -->
<script type="text/javascript">
$(document).ready(function(){
$( "#accordion" ).accordion({
autoHeight: false,
navigation: true
});
});
</script>
问题来了。第一个处罚被扩大为默认。当我单击不同的面板时,该面板下的内容未显示。它只是膨胀了一点点,然后就冻结在那里了。第一个面板也没有倒塌。所有面板都变得不可点击。就像下面的屏幕截图:
有趣的是,如果我将手风琴部分放在单独的 leftmenu.html 文件中并使用“$('#leftFrame').load(leftmenu.html)”将其加载到“leftFrame”div中。一切又恢复正常了。
我的第一个想法是主页中的其他一些 javascript 或 css 可能会影响这一点。我尝试注释掉部分然后所有其他 javascript 或 css。在使用 .load 函数正常工作时,它仍然无法在主页上工作。
知道为什么吗?
提前致谢 米洛
I was trying jQueryUI accordion. I created a test site, copied the code and put things in place. It works fine.
Then I tried to put it in my website. In my website, I have two menu. One is horizontal, on the top. The other is vertical, to the left. I intend to apply accordion to the vertical menu. The vertical menu will also change when different item in the top horizontal menu is clicked.
First thing I did was testing it on my homepage, just to see if there is any conflicts with my current design. The code for the vertical menu is like this:
<!-- leftFrame begin -->
<div id="leftFrame">
<div id="accordion">
<h3><a href="#section1">Section 1</a></h3>
<div>
<p>homepage11111111</p>
</div>
<h3><a href="#section2">Section 2</a></h3>
<div>
<p>homepage22222222</p>
</div>
<h3><a href="#section3">Section 3</a></h3>
<div>
<p>homepage33333333</p>
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
<a href="#othercontent">Link to other content</a>
</div>
</div>
</div> <!-- leftFrame end -->
<script type="text/javascript">
$(document).ready(function(){
$( "#accordion" ).accordion({
autoHeight: false,
navigation: true
});
});
</script>
Here came the problem. The first penal was expanded as default. When I clicked on a different panel, the content under that panel was not shown. It just expanded a little bit and froze there. The first panel did not collapse either. All panels became not click-able. Like the screenshot below:
Interesting thing was, if I put the accordion part in a seperate leftmenu.html file and use "$('#leftFrame').load(leftmenu.html)" to load it into the "leftFrame" div. Everything works again.
My first thought was some other javascript or css in the homepage might affect this. I tried to comment out part then all of other javascript or css. It was still not working on the homepage while working fine with the .load function.
Any idea why?
Thanks in advance
Milo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我原来是为了缓解不同js文件之间的冲突。只需确保仅使用一种版本的缓动函数即可。
I turned out to be an easing conflict between different js files. Just make sure to use only one version of easing function.
我知道您有答案,但对于其他人来说,当我通过克隆添加新部分时,我遇到了类似的问题,具有相同的奇怪行为。
我克隆了手风琴的第一个(唯一的)部分,将其附加到末尾,然后更改标题和内容以满足我的需要。之后,我销毁并重新添加了手风琴,以确保它可以与新内容配合使用。之后,多个(全新)部分显示为活动部分(由于克隆),当我单击它们时,它们最初会工作,但在某个时刻突然停止工作。
为了解决此问题,我执行了以下操作:
希望这对沿线的人有所帮助。
I know you have your answer, but for others, I had a similar issue with the same weird behavior when I was adding new sections via a clone.
I cloned the first (only) section of the accordion, appended it to the end, then changed the title and contents to suit my need. After that, I destroyed and re-added the accordion to ensure it worked with the new contents. After that, multiple (all new) sections showed as the active one (due to the clone) and when I clicked them, they would initially work but suddenly stop working at some point.
To resolve this issue, I did the following:
Hope this helps someone along the line.