Jquery 动画隐藏和显示
我希望当我点击链接时同时发生两件事。 我正在慢慢浏览 Jquery 文档,但尚未了解我需要什么。
这是我的网站的链接
当我点击服务链接时我希望隐藏 #slideshow
div
并用一个新的 div 来替换它。
我曾尝试在单击服务链接时让幻灯片以动画形式显示,但它要么执行动画功能,要么转到链接的 html 页面,而不是两者都执行。 我将如何实现两者。
无论我只是在同一页面上隐藏和显示 div,还是转到新的 html 页面,都没有关系。 我只想拥有动画功能并在隐藏动画功能的同时更改内容。
这是我正在使用的 jquery 代码,
$(document).ready(function(){
$("a.home").toggle(
function(){
$("#slideshow").animate({ height: 'hide', opacity: 'hide' }, 'slow');
},
function(){
$("#slideshow").animate({ height: 'show', opacity: 'show' }, 'slow');
}
);
});
$(document).ready(function(){
$("a.services").toggle(
function(){
$("#slideshow2").animate({ height: 'show', opacity: 'show' }, 'slow');
},
function(){
$("#slideshow2").animate({ height: 'hide', opacity: 'hide' }, 'slow');
}
);
});
主页和服务是两个链接,我希望服务在单击时隐藏 #slideshow
div
,并显示 Slideshow2
div
,它将被隐藏,然后替换第一个。
有相当多的 html,因此从链接查看我的源代码可能会更容易。
I would like to have two things happen at once when I click on a link. I am slowly going through Jquery documentation, but have yet to learn what I need yet.
Here is a link to my site
When I click on the services link I would Like the #slideshow
div
to hide, and a new div to replace it.
I had tried to just have the slideshow animate out on clicking the services link, but it would either do the animate function or go to the linked html page, not both. How would I accomplish both.
It doesn't matter if I just hide and show divs on the same page, or if I go to a new html page. I just want to have the animate function and change the content while hiding one.
this is the jquery code I am using
$(document).ready(function(){
$("a.home").toggle(
function(){
$("#slideshow").animate({ height: 'hide', opacity: 'hide' }, 'slow');
},
function(){
$("#slideshow").animate({ height: 'show', opacity: 'show' }, 'slow');
}
);
});
$(document).ready(function(){
$("a.services").toggle(
function(){
$("#slideshow2").animate({ height: 'show', opacity: 'show' }, 'slow');
},
function(){
$("#slideshow2").animate({ height: 'hide', opacity: 'hide' }, 'slow');
}
);
});
home and services are the two links, and I would like services when clicked to hide the #slideshow
div
, and show the slideshow2
div
, which would be hidden and then replace the first one.
there is a fair amount of html so it may be easier to view my source from the link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:此解决方案已根据评论中的后续问题进行更新。
您应该使用 显示/隐藏方法的回调方法。
回调方法是 .show/.hide 函数的第二个参数。 每当 .show/.hide 方法完成时就会运行它。 因此,您可以关闭/打开盒子,然后在回调方法中立即运行一个事件。
Updated: This solution was updated following a follow-up question in the comments.
You should use the callback method of the show/hide methods.
The callback method is the second parameter of the .show/.hide functions. It is ran whenever the .show/.hide method is completed. Therefore, you can close/open your box, and within the callback method run an event immediately afterwards.