本文實(shí)例講述了jQuery實(shí)現(xiàn)字體顏色漸變效果的方法。分享給大家供大家參考,具體如下:
jQuery不允許css屬性值為非數(shù)字的屬性進(jìn)行動(dòng)畫處理,
比如.animate(color:'red',500)或是.animate(fontWeight:'bold',500)都無法運(yùn)行,
因此如果想實(shí)現(xiàn)顏色漸變的效果需要animate()外的其他方法,示例如下
方法1:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src="http://libs.baidu.com/jquery/1.7.2/jquery.js"></script></head><body> <div class="b1" style="font-size: 50px;font-weight: bold;position: absolute;">BBB</div> <div class="b2" style="font-size: 50px;font-weight: bold;position: absolute;color: #f60;display: none;">BBB</div></body><script type="text/javascript">$(function(){ $('.b1').hover(function(){ $('.b2').fadeIn(500); })})</script></html>
設(shè)置一個(gè)和b1完全相同位置的b2并隱藏,添加hover事件使b2漸顯,用這個(gè)笨方法可模擬color漸變效果
方法2:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> div{ color: red; transition: color 1s; } div:hover{ color: yellow; } </style> <script type="text/javascript" src="d:/jquery-3.1.0.js"></script></head><body><div class="wrapper">1111</div><script type="text/javascript"></script></body></html>
利用css3的transition方法,實(shí)現(xiàn)鼠標(biāo)懸浮后,顏色漸變動(dòng)畫效果
PS:這里再為大家推薦幾款相關(guān)的顏色與特效工具供大家參考使用:
在線特效文字/彩色文字生成工具:
http://tools.VeVB.COm/aideddesign/colortext
在線彩虹文字/顏色漸變文字生成工具:
http://tools.VeVB.COm/aideddesign/txt_caihongzi
在線發(fā)光字生成工具:
http://tools.VeVB.COm/aideddesign/txt_faguangzi
仿古書排版文字豎排轉(zhuǎn)換工具:
http://tools.VeVB.COm/transcoding/shupai
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注