在 HTML5 中如何在 SVG 圓內顯示影像?


要在 SVG 圓中顯示影像,請使用 <circle> 元素並設定剪下路徑。<clipPath> 元素用於定義剪下路徑。SVG 中的影像使用 <image> 元素設定。

示例

可以嘗試執行以下程式碼以瞭解如何在 HTML5 中在 SVG 圓內顯示影像

即時演示

<!DOCTYPE html>
<html>
   <head>
      <title>HTML5 SVG Image</title>
   <head>
   <body>
      <svg width="500" height="350">
         <defs>
            <clipPath id="myCircle">
               <circle cx="250" cy="145" r="125" fill="#FFFFFF" />
            </clipPath>
         </defs>
         <image width="500" height="350" xlink:href="https://tutorialspoint.tw/videotutorials/images/coding_ground_home.jpg" clip-path="url(#myCircle)" />
      </svg>
   </body>
</html>

更新於: 2020-05-13

9K+ 瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.