我对JQuery比较陌生,我发现自己陷入了困境。基本上我尝试做的是将用户发送到不同的html页面,具体取决于他们使用.navmenu li选择的按钮。我已经让它适用于一个位置(index.html),但我不知道如何设置多个页面。 IE如果用户点击'项目li',我希望他们转到projects.html。这里的效果是当用户点击我的侧导航中的li时,div在删除类'.move-right'时滑出屏幕,等待.5s,然后重定向到新的html页面。有人可以建议吗?
$(document).ready(function(){
$('.navmenu').bind('click' , function(e){
e.preventDefault();
$('.left , .overleft').removeClass('move-right')
setTimeout(function(event) {
window.location.href = "index.html";
}, 500);
event.stopPropagation();
});
});
我的代码中可能还有一些其他错误,如果你能告诉我这会有所帮助。谢谢
答案 0 :(得分:2)
使用常规链接,例如
<ul class="navmenu"><li><a href="projects.html">See projects</a></li></ul>
然后在你的JS中:
// listen to click events on links in navmenu
$('.navmenu').on('click' , 'a', function(e){
e.preventDefault();
// the href attribute of clicked link
var url = this.href;
$('.left , .overleft').removeClass('move-right');
setTimeout(function(event) {
// redirect after 500ms
window.location.href = url;
}, 500);
event.stopPropagation();
});
这样链接功能完全正常,因此用户可以在新标签页中单击以打开,或者右键单击并在链接的上下文菜单中执行任何操作。