jquery悬停菜单和后退按钮
我有这段代码,但是当我单击浏览器中的后退按钮时,菜单仍然可见,并且它的类仍然是“显示”
$("#courses > a,#masterclasses > a,#the-team > a").click(function (e) {
e.preventDefault();
});
$('#courses > a,#courses-nav').hover(function(){
$('#courses-nav').addClass('show');
$('#courses > a').css('color','#43b2b0');
},function(){
$('#courses-nav').removeClass('show');
if ($('body').hasClass('courses')) {
$('#courses > a').css('color','#43b2b0');
}
else {
$('#courses > a').css('color','#000');
}
});
我尝试添加这个... $('#courses-nav,#masterclasses-nav,#the-team-nav').removeClass('show'); ...但这并不能解决问题。
感谢您为解决此问题提供的任何帮助。
C
I have this code, but when I click the back button in the browser the menu is still visible and it's class still is 'show'
$("#courses > a,#masterclasses > a,#the-team > a").click(function (e) {
e.preventDefault();
});
$('#courses > a,#courses-nav').hover(function(){
$('#courses-nav').addClass('show');
$('#courses > a').css('color','#43b2b0');
},function(){
$('#courses-nav').removeClass('show');
if ($('body').hasClass('courses')) {
$('#courses > a').css('color','#43b2b0');
}
else {
$('#courses > a').css('color','#000');
}
});
I have tried adding this...
$('#courses-nav,#masterclasses-nav,#the-team-nav').removeClass('show');
...but that doesn't fix the problem.
Thanks for any help in fixing this issue.
C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,当您使用后退和前进按钮时,当今的浏览器实际上不会重新加载页面。相反,他们保留旧页面,在离开时将其隐藏,并在重新进入页面时重新显示。这会带来更快的后退/前进导航,并且意味着当您返回时页面将处于与离开时完全相同的状态。 关于 Firefox 中的 bfcache。
您可以捕获 pageshow 事件并使用它来取消中间操作,而无需完全破坏 bfcache(通常通过添加 unload 事件处理程序来完成)。
对于悬停,您可能最好使用普通的 CSS
:hover
而不是脚本。只有 IE6 不支持此功能。再次强调,无论是使用脚本还是 CSS,悬停菜单都存在相当棘手的可用性和可访问性问题。Yeah, when you use the back and forward buttons, today's browsers don't actually reload the page. Instead, they keep the old page in existence, hide it when leaving, and re-show it when re-entering the page. This results in much faster back/forward navigation, and means that the page will be in the exact same state when you go back to it as it was when you left it. About the bfcache in Firefox.
You can catch the
pageshow
event and use it to cancel intermediate operations without going so far as to break the bfcache completely (which is usually done by adding anunload
event handler).For hovers you may be better off using normal CSS
:hover
rather than scripting. It's only IE6 this doesn't work with. There again, hover-menus have quite tricky usability and accessibility problems whether done with script or CSS.