<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          一篇文章帶你了解SVG 陰影

          共 3312字,需瀏覽 7分鐘

           ·

          2021-03-01 23:36

          點擊上方“前端進階學(xué)習(xí)交流”,進行關(guān)注

          回復(fù)“前端”即可獲贈前端相關(guān)學(xué)習(xí)資料

          花開堪折直須折,莫待無花空折枝。

          注意: Internet Explorer和Safari不支持SVG濾鏡!

          一、前言

          defs 和 filte元素

          所有互聯(lián)網(wǎng)的SVG濾鏡定義在<defs>元素中。<defs>元素定義短并含有特殊元素(如濾鏡)定義<filter>標(biāo)簽用來定義SVG濾鏡。

          <filter>標(biāo)簽使用必需的id屬性來定義向圖形應(yīng)用哪個濾鏡?


          二、feOffset 元素

          1. 實例 1

          <feOffset>元素是用于創(chuàng)建陰影效果。我的想法是采取一個SVG圖形(圖像或元素)并移動它在xy平面上一點兒。

          偏移一個矩形(帶<feOffset>),然后混合偏移圖像頂部(含<feBlend>)。

          <!DOCTYPE html><html><body style="background-color: aqua;">
          <p><b>Note: </b>Internet Explorer and Safari do not support SVG filters yet!</p>
          <svg xmlns="http://www.w3.org/2000/svg" version="1.1"><defs><filter id="f1" x="0" y="0" width="200%" height="200%"><feOffset result="offOut" in="SourceGraphic" dx="20" dy="20" /><feBlend in="SourceGraphic" in2="offOut" mode="normal" /></filter></defs><rect width="90" height="90" stroke="green" stroke-width="3" fill="red" filter="url(#f1)" /></svg>
          </body></html>

          運行效果:

          a5f2dbf5dc90bd6f1e72ad5092d18b47.webp

          代碼解析:

          1. <filter>元素id屬性定義一個濾鏡的唯一名稱。

          2. <rect>元素的濾鏡屬性用來把元素鏈接到"f1"濾鏡。


          2. 實例 2

          現(xiàn)在,偏移圖像可以變的模糊(含 <feGaussianBlur>)。

          代碼:

          <svg xmlns="http://www.w3.org/2000/svg" version="1.1"><defs><filter id="f1" x="0" y="0" width="200%" height="200%"><feOffset result="offOut" in="SourceGraphic" dx="20" dy="20" /><feGaussianBlur result="blurOut" in="offOut" stdDeviation="10" /><feBlend in="SourceGraphic" in2="blurOut" mode="normal" /></filter></defs><rect width="90" height="90" stroke="green" stroke-width="3" fill="red" filter="url(#f1)" /></svg>

          運行效果

          e25af4316a2452e650b4a7aa4711f049.webp

          代碼解析:

          ?<feGaussianBlur>元素的stdDeviation屬性定義了模糊量。


          3. 實例 3

          現(xiàn)在,制作一個黑色的陰影。

          代碼:

          <svg xmlns="http://www.w3.org/2000/svg" version="1.1"><defs><filter id="f1" x="0" y="0" width="200%" height="200%"><feOffset result="offOut" in="SourceAlpha" dx="20" dy="20" /><feGaussianBlur result="blurOut" in="offOut" stdDeviation="10" /><feBlend in="SourceGraphic" in2="blurOut" mode="normal" /></filter></defs><rect width="90" height="90" stroke="green" stroke-width="3" fill="red" filter="url(#f1)" /></svg>

          運行效果

          aab0e8ddd126a6e85f5089a288216e11.webp

          代碼解析:

          ? <feOffset>元素的屬性改為"SourceAlpha"在Alpha通道使用殘影,而不是整個RGBA像素。


          4. 實例 4

          現(xiàn)在為陰影涂上一層顏色。

          代碼:

          <svg xmlns="http://www.w3.org/2000/svg" version="1.1"><defs><filter id="f1" x="0" y="0" width="200%" height="200%"><feOffset result="offOut" in="SourceGraphic" dx="20" dy="20" /><feColorMatrix result="matrixOut" in="offOut" type="matrix" values="0.2 0 0 0 0 0 0.2 0 0 0 0 0 0.2 0 0 0 0 0 1 0" /><feGaussianBlur result="blurOut" in="matrixOut" stdDeviation="10" /><feBlend in="SourceGraphic" in2="blurOut" mode="normal" /></filter></defs><rect width="90" height="90" stroke="green" stroke-width="3" fill="red" filter="url(#f1)" /></svg>

          eaf5ccfc2014b4a7ceb29965309b0042.webp

          代碼解析:

          ? ?<feColorMatrix>過濾器是用來轉(zhuǎn)換偏移的圖像使之更接近黑色的顏色。'0.2'矩陣的三個值都獲取乘以紅色,綠色和藍色通道。降低其值帶來的顏色至黑色(黑色為0)。


          三、總結(jié)

          本文基于Htm基礎(chǔ),主要介紹了通過SVG進行圖像,陰影效果的呈現(xiàn),feOffset元素在實際應(yīng)用中對圖像的陰影添加不一樣的樣式 ,呈現(xiàn)不一樣的陰影層次。通過豐富的案例分析,效果圖的展示,讓讀者能夠更好理解和學(xué)習(xí)。

          大家積極嘗試,有時候看到別人實現(xiàn)起來很簡單,但是到自己動手實現(xiàn)的時候,總會有各種各樣的問題,切勿眼高手低,勤動手,才可以理解的更加深刻。

          代碼很簡單,希望能夠幫助你學(xué)習(xí)。

          -------------------?End?-------------------

          往期精彩文章推薦:

          2b0de633da06de875a48f6e8be6bc606.webp

          歡迎大家點贊,留言,轉(zhuǎn)發(fā),轉(zhuǎn)載,感謝大家的相伴與支持

          想加入前端學(xué)習(xí)群請在后臺回復(fù)【入群

          萬水千山總是情,點個【在看】行不行

          瀏覽 36
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  黄色www.| 可以看的毛片 | 成人av影视在线观看国产高清 | 欧美操逼虐待视频网 | 人妻免费在线视频 |