基於SVG.js實現網頁初始化線條描繪效果

來源:互聯網
上載者:User

標籤:raw   ack   dom   .net   解釋   init   決定   add   round   

  前端實現看到一個網頁的效果很cool(參考https://tympanus.net/Development/SVGDrawingAnimation/index2.html),決定自己去實現以下這個效果,並且封裝成一個js外掛程式供大家簡單去實現該效果;

  目前,已經實現了三種效果(描繪容器的邊框,描繪線狀統計圖樣式,描繪餅狀統計圖樣式);

 

  使用方法:

  1、首先引入jquery和svg.js

  2、然後引入svg.webInitAnimation.js

  3、定義自己的dom元素

  4、選擇想要繪製的樣式添加到class屬性中

  如下

  

<html><head>    <script type="text/javascript" src="jquery-1.9.1.min.js"></script>    <script type="text/javascript" src="svg.js"></script>    <script type="text/javascript" src="svg.webInitAnimation.js"></script></head><body class="bg-fill" style="background-color:#07263B;margin:0;padding:0;">    <div style="margin-top:20px;text-align:center;">        <span class="init_border">fdsgfsdgfdsg</span>    </div>    <span class="init_border" style="margin-left:100px;">fdsafdas</span>    <div class="init_chartline init_border" style="margin-left:400px;margin-top:50px; background-color: red; width:300px;height:200px;"></div>    <div class="init_pie" style="margin-left:200px;margin-top:50px; background-color: red; width:300px;height:300px;"></div></body></html>

 

 

  用法解釋:

  首先如果你想要背景色填充動畫樣式,在body節點添加bg-fill類,並且設定body的背景色,如果不需要該效果則不需添加樣式和class

  邊框描繪:選擇你想要描繪邊框的dom在class中添加init_border類即可,

  線狀統計圖樣式:選擇你需要繪製該樣式的dom添加init_chartline類即可,

  餅狀統計圖樣式:選擇你需要繪製該樣式的dom添加init_pie類即可

 

  以上的樣式效果可以在同一dom上添加,最好是init_border和其他樣式配合使用

  

  注意:

  在邊框描繪樣式中如果選擇的是文字的邊框,請確保選擇的dom是完整包圍文字的,最好選擇行內元素,塊狀元素(例如<div style="width:100%;text-align:center;">testtext</div>)則不能確點描繪的是文字的邊框而是div塊狀元素的邊框了

 

  後續會添加更多的樣式效果請關注我的github

基於SVG.js實現網頁初始化線條描繪效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.