admin管理员组文章数量:1295267
I have the following code:
This is a <span id="sentence">sentence</span>.
When a user hovers over sentence
, I would like an underline to fade in under the word.
This seems like such a simple problem, but I have not been able to figure out how best to do it. Just to be clear, I cannot just use css:hover
. I need to do this with JQuery given the actual problem is more plicated and requires more control than that illustrated here. Thanks very much for your help in advance.
I have the following code:
This is a <span id="sentence">sentence</span>.
When a user hovers over sentence
, I would like an underline to fade in under the word.
This seems like such a simple problem, but I have not been able to figure out how best to do it. Just to be clear, I cannot just use css:hover
. I need to do this with JQuery given the actual problem is more plicated and requires more control than that illustrated here. Thanks very much for your help in advance.
3 Answers
Reset to default 4This might not fit your needs, and I realize you specifically don't want to use CSS. But just in case...
HTML
This is a <span id="sentence">sentence.</span>
CSS
span {
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
transition: all 0.5s;
border-bottom: 1px solid transparent;
}
span.clicked {
border-bottom: 1px solid black;
}
Script
$('span').click(function(){
$(this).addClass('clicked');
});
http://jsfiddle/as42u/4/
How about the Animated Underlines with jQuery plugin?
1. Use the underline jQuery plugin as Cymen suggested
Don't forget to add the required CSS to your stylesheet
2. Do it yourself
$("#sentence").hover(function(){
$(this).animate({
borderBottomWidth: "1px"
}, 500);
});
Example fiddle. You have to use a bottom border because jQuery doesn't know how to animate the text-decoration property.
本文标签: javascriptHow can I fade in textdecoration css with jqueryStack Overflow
版权声明:本文标题:javascript - How can I fade in text-decoration css with jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741615953a2388527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论