javascript onclick fade div in (短代码)
我到处寻找,但在任何地方都找不到我想要的东西。
html结构基本上就是。
<ul>
<li><a href="">link</a></li>
<div id="us">hidden info</div>
</ul>
CSS结构是。
#us {display:none}
我希望这样当单击“link”时,div“us”从dipslay:none更改为dipslay:none;显示:阻止,以尽可能少的代码行优雅地淡入淡出,然后在单击链接时再次切换回显示:隐藏。
我知道有很多东西可以做到这一点,但我真的在寻找代码的简单性。
谢谢你的时间x
i'm been lookin all over the place and cannot find exactly what im after anywhere.
the html structure is basically.
<ul>
<li><a href="">link</a></li>
<div id="us">hidden info</div>
</ul>
the css structure is.
#us {display:none}
I'd like it so when "link" is clicked the div "us" is changed from dipslay:none; to display:block, in a graceful fade in as little lines of code as possible, and then again when the link is clicked its toggled back to display:hidden.
I'm aware that there are lots of things that can do this, but im really lookin for that simplicity in code.
thanks for your time x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以只使用
.toggle()
和持续时间(适用于所有 jQuery 版本),例如 或者,如果您使用的是 jQuery 1.4.4+,请使用
.fadeToggle()
像这样:但请注意,
不是
的有效子级,因此它可能会在多个浏览器中意外呈现......它'最好使用正确的标记。
You can just use
.toggle()
with a duration (works in all jQuery versions), like this:Or, if you're on jQuery 1.4.4+, use
.fadeToggle()
like this:Note though, a
<div>
isn't a valid child of<ul>
, so it may render unexpectedly in several browsers...it'd be better to use proper markup.像这样的东西:
Something like this:
由于 jQuery 核心中没有淡入淡出切换功能,我将使用:
As there is no fade-toggle in the jQuery core, I'd use:
如果 jQuery UI 适合您,我只能推荐它。
jQuery UI 扩展了 jQuery,具有许多不错的效果:
但是请查看网站本身: http://jqueryui.com/demos/显示/
If jQuery UI is an option for you, I can only recommend it.
jQuery UI extends jQuery with many nice effects:
But check out the website itself: http://jqueryui.com/demos/show/
感谢大家的意见!你很有帮助!我使用的最后一个我认为最合适的片段来自尼克。
所以再次感谢大家!并希望其他人能发现这很有用! x
thank you everybody for your input! You've been very helpful! The final snippet I've used which i deemed most appropriate was from Nick.
so thanks again everybody! and hope someone else can find this useful! x