標籤:css3 文字效果 陰影文字
前段時間一直在忙微課比賽的事情,部落格更新比較少,抱歉,今天抽空一更。
1.簡介
前面我們曾經用兩篇文章《純CSS3文字效果推薦》、《CSS3立體文字最佳實務》給大家介紹過利用CSS3 text-shaodwo實現陰影文字、立體文字效果,但是純css3實現的方式也有局限性,比如大量應用時會延緩頁面載入速度,效果的可控制性不強,今天給大家推薦一個js外掛程式來彌補這些缺失,隆重推出shine.js。
大家可以看看這篇文章《Better than Pure CSS3》學學使用方法,也可以到官方網站具體學習。
2.使用步驟a. 引入外掛程式
<script src="path/to/shine.min.js"></script>
b. 執行個體化shine.js
//預設參數執行個體化,my-shine-object為需要添加陰影的元素var shine = new Shine(document.getElementById(‘my-shine-object‘));
我們也可以先設定參數,然後執行個體化對象
var shine_config = new shinejs.Config({numSteps: 10,offset = 0.25,blur: 100,opacity: 0.5,shadowRGB: new shinejs.Color(255, 0, 0)});var shine = new Shine(document.getElementById("my-shine-object"), shine_config);c. 陰影的相關操作我們可以設定陰影的滑鼠移動響應
window.addEventListener(‘mousemove‘, function(event) { shine.light.position.x = event.clientX; shine.light.position.y = event.clientY; shine.draw();}, false);3.API詳解API詳解請大家參考官方github首頁。a.構造方法
Shine(domElement, optConfig, optClassPrefix, optShadowProperty)
| Parameter |
Type |
Description |
| domElement |
!HTMLElement |
應用陰影的元素 |
| optConfig |
?shinejs.Config= |
儲存陰影參數的設定物件(Optional config instance),可省略,如果省略將傳遞預設參數。 |
| optClassPrefix |
?string= |
給所有的陰影對象增加首碼,預設為shine-。 |
| optShadowProperty |
?string= |
Optional property name that the shadow will be applied to. Overrides the automatic detection for use of eithertextShadow or boxShadow. The value will be applied aselement.style[shadowProperty] = ‘...‘ and automatically prefixed for legacy browsers (e.g. MozBoxShadow). |
b.常用方法
Shine.prototype.draw()Shine.prototype.destroy()Shine.prototype.updateContent(optText)Shine.prototype.enableAutoUpdates()Shine.prototype.disableAutoUpdates()
c. 常用屬性
| Property |
Type |
Description |
| domElement |
HTMLElement |
The DOM element to apply the shine effect to. |
| config |
shinejs.Config |
Stores all config parameters. |
| light |
shinejs.Light |
Stores the light position and intensity. |
Enjoy it.
----------------------------------------------------------
前端開發whqet,關注web前端開發,分享相關資源,歡迎點贊,歡迎拍磚。
---------------------------------------------------------------------------------------------------------