html jquery动画,javascript – 动画HTML文本更改jQuery

这篇博客探讨了如何使用jQuery来创建文本动画,包括改变不透明度和宽度。示例代码展示了在鼠标悬停时,如何使文本元素的不透明度从1变为0并切换内容,然后在2秒内回弹到1。此外,还展示了如何通过动画调整文本元素的宽度,从当前宽度缩小到0,然后在完成时扩展回300px,同时改变文本内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

您目前的方式是语法不正确,也无法为文本设置动画,而是需要为包含文本的元素设置动画.还不清楚你想要制作什么样的动画,这里有几个例子:

动画不透明度:

$("div#title").hover(

function () {

$(this).stop().css('opacity', '0').html(function (_, oldText) { // Set the opacity of the div to 0 and then change the html (flip it based on last value)

return oldText == 'Good Bye' ? 'Hello' : 'Good Bye'

}).animate({

opacity: 1 // Animate opacity to 1 with a duration of 2 sec

}, 2000);

});

动画宽度:

$("div#title").hover(

function () {

$(this).stop().animate({

'width': '0px' // Animate the width to 0px from current width

}, 2000, function () { // On completion change the text

$(this).html(function (_, oldText) {

return oldText == 'Good Bye' ? 'Hello' : 'Good Bye'

}).animate({ // and animate back to 300px width.

'width': '300px'

}, 2000);

})

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值