jQuery 内容在 .load() 成功期间不会淡入
我已经研究过几个类似的问题,但似乎没有一个起作用。我正在尝试使用 jQuery 单击事件来 fadeOut() 目标 div,从单击的元素的 href 异步加载() 目标 div 的内容,然后 fadeIn() 新内容。
有问题的网站是 http://clients.weareno1.com/worklocal.org/。
我的代码如下:
$(document).ready(function() {
$("#pri_nav a").click(function() {
$("#content").fadeOut(400, "linear").load(this.href, function() {
$("#content").fadeIn(800, "linear");
});
});
});
设置将 'e' 传递给 click 函数(即 $("#pri_nav a").click(function(e) {e.preventDefault(); [....] 让我完成了大部分工作,但随后我不得不手动删除并替换锚点的父 li 中的“选定”类。最坏的情况,这就是我要做的,但似乎有点不必要的复杂。
非常感谢
您的宝贵时间。
I've poked around through several similar issues, but none seem to have worked. I am trying to use a jQuery click event to fadeOut() a target div, asynchronously load() the target div's content from the clicked element's href, and then fadeIn() the new content.
The site in question is http://clients.weareno1.com/worklocal.org/.
My code is as follows:
$(document).ready(function() {
$("#pri_nav a").click(function() {
$("#content").fadeOut(400, "linear").load(this.href, function() {
$("#content").fadeIn(800, "linear");
});
});
});
Setting passing 'e' to the click function (i.e. $("#pri_nav a").click(function(e) {e.preventDefault(); [....]
gets me most of the way there, but then I'm left to manually strip and replace the "selected" class from the anchor's parent li. Worst case, that's what I'll do, but it seems a little unnecessarily complicated.
Any input would be most appreciated.
Thanks in advance for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在评论中提到了 SEO 收益。搜索引擎不执行 JavaScript 代码。只要您的应用程序在 JavaScript 关闭的情况下工作,搜索引擎(以及有辅助功能需求的人)就能够跟踪链接。
fade*
方法不是同步的。我不会那样链接负载。You mention in your comments about SEO gains. Search engines don't execute JavaScript code. As long as your application works with JavaScript turned off, search engines (and people with accessibility needs) will be able to follow links.
The
fade*
methods are not synchronous. I wouldn't chain load like that.