jQuery 切换下划线
我有一个通过单击链接进行切换的菜单。我希望该链接在菜单可见时带有下划线,并且在隐藏时没有任何装饰。我无法正确使用该功能:当您第一次按下触发按钮时会显示下划线,但在隐藏菜单后仍会保留下划线。
感谢您的帮助!
HTML
<div id="trigger">
<div id="menu">MENU<br/></div>
<div id="navdrop">
<a class="a transition" id="item1" href="Pages/music.html" alt="MUSIC">MUSIC</a><br />
<a class="a transition" id="item2" href="Pages/photos.html" alt="PHOTOS">PHOTOS</a><br />
<a class="a transition" id="item3" href="Pages/biography.html" alt="BIOGRAPHY">BIOGRAPHY</a><br />
<a class="a transition" id="item4" href="Pages/discography.html" alt="DISCOGRAPHY">DISCOGRAPHY</a><br />
<a class="a transition" id="item5" href="Pages/contact.html" alt="CONTACT">CONTACT</a><br />
<a class="a" id="item6" href="http://www.blog.fernandogaribay.com" alt="BLOG" target="_blank">BLOG</a><br />
</div>
</div>
JavaScript
$('#trigger').click(function (){
$('#navdrop').slideToggle(400);
$('#menu').css("text-decoration", "underline");
});
I've got a menu that toggles by clicking a link. I'd like that link to underline when the menu is visibile, and have no decoration when it's hidden. I can't get the function correct: the underline displays when you first press the trigger button, but stays after the menu is hidden.
Thanks for your help!
HTML
<div id="trigger">
<div id="menu">MENU<br/></div>
<div id="navdrop">
<a class="a transition" id="item1" href="Pages/music.html" alt="MUSIC">MUSIC</a><br />
<a class="a transition" id="item2" href="Pages/photos.html" alt="PHOTOS">PHOTOS</a><br />
<a class="a transition" id="item3" href="Pages/biography.html" alt="BIOGRAPHY">BIOGRAPHY</a><br />
<a class="a transition" id="item4" href="Pages/discography.html" alt="DISCOGRAPHY">DISCOGRAPHY</a><br />
<a class="a transition" id="item5" href="Pages/contact.html" alt="CONTACT">CONTACT</a><br />
<a class="a" id="item6" href="http://www.blog.fernandogaribay.com" alt="BLOG" target="_blank">BLOG</a><br />
</div>
</div>
Javascript
$('#trigger').click(function (){
$('#navdrop').slideToggle(400);
$('#menu').css("text-decoration", "underline");
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
css
移动演示
css
demo on the go
您需要使用 .slideToggle() 的回调部分,
这将在幻灯片完成后触发 css 更改。
我还建议您在 css 中设置一个
.underline
类来设置下划线。正如其他人一样,我也会为您提供 css 规则,非常基本。使用通用.underline
还可以提高可重用性,因为您可以在站点中的任何位置使用它来设置下划线文本装饰you need to use the callback portion of the .slideToggle()
This will trigger the css change after the slide has completed.
I also suggest you set up a
.underline
class in your css to set the underline. As others have I will also give you the css rule for this, very basic. Using a generic.underline
also improves reusability as you can use it anywhere in your site to set the underline text-decoration