jQueryUI 选项卡:悬停时停止旋转
我使用 jqueryUI 构建了一些旋转选项卡。当用户将鼠标移动到选项卡式菜单和选项卡式内容上时,选项卡应停止旋转。我读了有用的教程,但它对我不起作用。
尽管我将光标移到选项卡上,选项卡仍然保持旋转。当我将鼠标悬停在 div#menu-prime
上时,选项卡的行为很愚蠢!
<script type="text/javascript">
$(document).ready(function(){
$("#menu-prime").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 3000);
$('#menu-prime').hover(function(){
$(this).tabs('rotate', 0, false);
},function(){
$(this).tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 3000);
}
);
});
</script>
<div id="menu-prime">
<ul class="ui-tabs-nav">
<li id="nav-fragment-1" class="ui-tabs-nav-item ui-tabs-selected"><a href="#fragment-1">Kochen</a></li>
<li id="nav-fragment-2" class="ui-tabs-nav-item"><a href="#fragment-2">Wohnen</a></li>
<li id="nav-fragment-3" class="ui-tabs-nav-item"><a href="#fragment-3">Schlafen</a></li>
<li id="nav-fragment-4" class="ui-tabs-nav-item"><a href="#fragment-4">Mehr</a></li>
</ul>
<div id="fragment-1" class="ui-tabs-panel" style="">Content 1</div>
<div id="fragment-2" class="ui-tabs-panel" style="">Content 2</div>
<div id="fragment-3" class="ui-tabs-panel" style="">Content 3</div>
<div id="fragment-4" class="ui-tabs-panel" style="">Content 4</div>
</div>
谢谢, Johannes
编辑:增强
感谢 Kim,旋转选项卡现在会在用户将鼠标悬停在其中一个选项卡上时等待。
$("#menu-prime").tabs({ fx: {opacity: 'toggle', duration:100} }).tabs('rotate', 3000, true);
$('#menu-prime').mouseover(function(){
$(this).tabs('rotate', 0, false);
});
$('#menu-prime').mouseout(function(){
$(this).tabs({ fx: {opacity: 'toggle', duration:100} }).tabs('rotate', 3000);
});
最初希望选项卡在鼠标悬停时发生变化,而不是在单击时发生变化。因此,我修改了 Kim 的代码:
$("#menu-prime").tabs({ fx: {opacity: 'toggle', duration:100} }).tabs({event: 'mouseover'}).tabs('rotate', 3000, true);
$('#menu-prime').mouseover(function(){
$(this).tabs('rotate', 0, false);
});
$('#menu-prime').mouseout(function(){
$(this).tabs({ fx: {opacity: 'toggle', duration:100} }).tabs({event: 'mouseover'}).tabs('rotate', 3000);
});
现在,一旦用户将鼠标悬停在任何选项卡上,选项卡,尤其是自动旋转的行为就会非常奇怪。我猜这两个鼠标悬停事件使彼此变得复杂?
i build some rotatings tabs, using jqueryUI. While the user moves the mouse over the tabbed menu and tabbed content, the tabs should stop rotating. I read a useful tutorial, but it doesn't work for me.
The tabs still keep rotating though i move the cursor over them. Once i hovered the div#menu-prime
, the tabs behave silly!
<script type="text/javascript">
$(document).ready(function(){
$("#menu-prime").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 3000);
$('#menu-prime').hover(function(){
$(this).tabs('rotate', 0, false);
},function(){
$(this).tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 3000);
}
);
});
</script>
<div id="menu-prime">
<ul class="ui-tabs-nav">
<li id="nav-fragment-1" class="ui-tabs-nav-item ui-tabs-selected"><a href="#fragment-1">Kochen</a></li>
<li id="nav-fragment-2" class="ui-tabs-nav-item"><a href="#fragment-2">Wohnen</a></li>
<li id="nav-fragment-3" class="ui-tabs-nav-item"><a href="#fragment-3">Schlafen</a></li>
<li id="nav-fragment-4" class="ui-tabs-nav-item"><a href="#fragment-4">Mehr</a></li>
</ul>
<div id="fragment-1" class="ui-tabs-panel" style="">Content 1</div>
<div id="fragment-2" class="ui-tabs-panel" style="">Content 2</div>
<div id="fragment-3" class="ui-tabs-panel" style="">Content 3</div>
<div id="fragment-4" class="ui-tabs-panel" style="">Content 4</div>
</div>
THANKS,
Johannes
EDIT: Enhancement
Thanks to Kim, the rotating tabs now wait when the user hovers one of the tabs.
$("#menu-prime").tabs({ fx: {opacity: 'toggle', duration:100} }).tabs('rotate', 3000, true);
$('#menu-prime').mouseover(function(){
$(this).tabs('rotate', 0, false);
});
$('#menu-prime').mouseout(function(){
$(this).tabs({ fx: {opacity: 'toggle', duration:100} }).tabs('rotate', 3000);
});
Originally wanted the tabs to change on mouseover not on click. Therefore i modified Kim’s code:
$("#menu-prime").tabs({ fx: {opacity: 'toggle', duration:100} }).tabs({event: 'mouseover'}).tabs('rotate', 3000, true);
$('#menu-prime').mouseover(function(){
$(this).tabs('rotate', 0, false);
});
$('#menu-prime').mouseout(function(){
$(this).tabs({ fx: {opacity: 'toggle', duration:100} }).tabs({event: 'mouseover'}).tabs('rotate', 3000);
});
Now the tabs and especially the auto-rotating behave very strange once the user hovered any tab. I guess the two mouseover-events complicate each other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
编辑:
你在同一事件中做了不同的事情。所以你应该将你的代码更改为:
并删除
Try this instead:
Edit:
you are doing to different things on the same event. so you should proberly change your code to this:
and remove
jQuery UI 自 1.9 以来发生了很多变化,现在旋转选项卡和悬停暂停只能与扩展一起使用。对于悬停 - 只需使用我的扩展 jQuery UI 选项卡:悬停时暂停< /a>
jQuery UI since 1.9 has a lot of changes, now rotating tabs and pause on hover you can use only with extensions. For hover - just use my extension jQuery UI Tabs: Pause on Hover