如何在 jQuery 中添加加载页面点击功能?
我正在使用以下脚本来关闭联系人面板:
<script type="text/javascript">
$(document).ready(function(){
$("#home").click(function(){
$("#panel").slideUp("slow");
$(this).toggleClass("top-current");
$(this).toggleClass("top");
$("#contact").toggleClass("top-current");
$("#contact").toggleClass("top");
return false;
});
});
</script>
由于我在不同页面上使用相同的脚本,如果用户位于主页以外的页面上,那么我需要向脚本添加更多内容,以便主页面板关闭后加载(index.html)。所以我想我需要延迟,然后加载 index.html 页面,但我不确定如何在 jQuery 中执行此操作,并且将不胜感激。
谢谢,
尼克
I am using the following script to close a contact panel:
<script type="text/javascript">
$(document).ready(function(){
$("#home").click(function(){
$("#panel").slideUp("slow");
$(this).toggleClass("top-current");
$(this).toggleClass("top");
$("#contact").toggleClass("top-current");
$("#contact").toggleClass("top");
return false;
});
});
</script>
As I am using the same script on different pages, if the user is on a page other than the home page then I need to add more to the script so that the home page is loaded (index.html) after the panel has closed. So I guess I would need a delay and then the index.html page to load, but I am not sure how to do this in jQuery, and would be grateful for some help.
Thanks,
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设当您说需要添加延迟时,您的意思是要等到滑动动画完成。您可以为
slideUp
方法提供回调函数,该函数将在动画完成。在该回调中,您可以将用户发送到您的主页:I assume that when you say you need to add a delay, what you mean is that you want to wait until the sliding animation has finished. You can provide a callback function to the
slideUp
method which will run when the animation is complete. In that callback, you can send the user to your home page: