I have the following code:
This is a <span id="sentence">sentence</span>.
当用户将鼠标悬停在sentence
上方时,我希望单词下方出现一个淡入的下划线。
这似乎是一个非常简单的问题,但我一直没有找到最好的解决方法。需要明确的是,我不能只使用css:hover
。由于实际问题更复杂,需要比此处所示的更多的控制,因此我需要使用JQuery来完成此操作。非常感谢您提前的帮助。
I have the following code:
This is a <span id="sentence">sentence</span>.
当用户将鼠标悬停在sentence
上方时,我希望单词下方出现一个淡入的下划线。
这似乎是一个非常简单的问题,但我一直没有找到最好的解决方法。需要明确的是,我不能只使用css:hover
。由于实际问题更复杂,需要比此处所示的更多的控制,因此我需要使用JQuery来完成此操作。非常感谢您提前的帮助。
这可能不符合你的需求,我知道你不想使用CSS。但以防万一...
This is a <span id="sentence">sentence.</span>
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;
}
$('span').click(function(){
$(this).addClass('clicked');
});
$("#sentence").hover(function(){
$(this).animate({
borderBottomWidth: "1px"
}, 500);
});