超越純CSS3,超贊陰影製作效果推薦-shine.js

來源:互聯網
上載者:User

標籤: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前端開發,分享相關資源,歡迎點贊,歡迎拍磚。
---------------------------------------------------------------------------------------------------------

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.