標籤:des style blog http color java 使用 os
前段時間一直在忙微課比賽的事情,部落格更新比較少,抱歉,今天抽空一更。
1.簡介
前面我們曾經用兩篇文章《純CSS3文字效果推薦》、《CSS3立體文字最佳實務》給大家介紹過利用CSS3 text-shaodwo實現陰影文字、立體文字效果,但是純css3實現的方式也有局限性,比如大量應用時會延緩頁面載入速度,效果的可控制性不強,今天給大家推薦一個js外掛程式來彌補這些缺失,隆重推出shine.js。
大家可以看看這篇文章《Better than Pure CSS3》學學使用方法,也可以到官方網站具體學習。
2.使用步驟a. 引入外掛程式[html] view plaincopy
- <script src="path/to/shine.min.js"></script>
b. 執行個體化shine.js[javascript] view plaincopy
- //預設參數執行個體化,my-shine-object為需要添加陰影的元素
- var shine = new Shine(document.getElementById(‘my-shine-object‘));
我們也可以先設定參數,然後執行個體化對象[javascript] view plaincopy
- var shine_config = new shinejs.Config({
- numSteps: 10,
- offset = 0.25,
- blur: 100,
- opacity: 0.5,
- <span style="white-space:pre"> </span>shadowRGB: new shinejs.Color(255, 0, 0)
- });
- var shine = new Shine(document.getElementById("my-shine-object"), shine_config);
c. 陰影的相關操作我們可以設定陰影的滑鼠移動響應[javascript] view plaincopy
- 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.構造方法[javascript] view plaincopy
- 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. |