本文實例講述了jQuery實現字體顏色漸變效果的方法。分享給大家供大家參考,具體如下:
jQuery不允許css屬性值為非數字的屬性進行動畫處理,
比如.animate(color:'red',500)或是.animate(fontWeight:'bold',500)都無法運行,
因此如果想實現顏色漸變的效果需要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>
設置一個和b1完全相同位置的b2并隱藏,添加hover事件使b2漸顯,用這個笨方法可模擬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方法,實現鼠標懸浮后,顏色漸變動畫效果
PS:這里再為大家推薦幾款相關的顏色與特效工具供大家參考使用:
在線特效文字/彩色文字生成工具:
http://tools.VeVB.COm/aideddesign/colortext
在線彩虹文字/顏色漸變文字生成工具:
http://tools.VeVB.COm/aideddesign/txt_caihongzi
在線發光字生成工具:
http://tools.VeVB.COm/aideddesign/txt_faguangzi
仿古書排版文字豎排轉換工具:
http://tools.VeVB.COm/transcoding/shupai
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結》、《jquery中Ajax用法總結》、《jQuery表格(table)操作技巧匯總》、《jQuery擴展技巧總結》、《jQuery常見經典特效匯總》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答