当前位置: 首页>>代码示例>>用法及示例精选>>正文


HTML canvas shadowOffsetY用法及代码示例

canvas shadowOffsetY属性用于设置或返回阴影与形状的垂直距离。此属性保持正值或负值,其中正值指示底部阴影,负值指示顶部阴影。

用法:

context.shadowOffsetY = number

属性值:


  • number:用于设置代表阴影的垂直距离的正数或负数。

示例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        HTML canvas shadowOffsetY Property 
    </title> 
</head> 
  
<body> 
    <canvas id="GFG"
            width="500" 
            height="300"> 
  </canvas> 
  
    <script> 
        var x = 
            document.getElementById("GFG"); 
        var contex = 
            x.getContext("2d"); 
        contex.shadowBlur = 20; 
        
        // vertical distance of shadow 
        contex.shadowOffsetY = 40; 
        contex.shadowColor = "blue"; 
        contex.fillStyle = "green"; 
        contex.fillRect(50, 50, 350, 200); 
        contex.stroke(); 
    </script> 
  
</body> 
  
</html>

输出:

示例2:

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        HTML canvas shadowOffsetY Property 
    </title> 
</head> 
  
<body> 
    <canvas id="GFG" 
            width="500"
            height="300"> 
  </canvas> 
  
    <script> 
        var x = 
            document.getElementById("GFG"); 
        var contex = 
            x.getContext("2d"); 
        contex.shadowBlur = 5; 
  
        // vertical distance of shadow. 
        contex.shadowOffsetY = -40; 
        contex.shadowColor = "rgb(0, 153, 0)"; 
        contex.fillStyle = "rgb(255, 0, 255)"; 
        contex.fillRect(50, 50, 350, 200); 
        contex.stroke(); 
    </script> 
  
</body> 
  
</html>

输出:

支持的浏览器:

  • 谷歌浏览器
  • Internet Explorer 9.0
  • 火狐浏览器
  • 苹果浏览器
  • Opera


相关用法

注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 HTML | canvas shadowOffsetY Property。非经特殊声明,原始代码版权归原作者所有,本译文的传播和使用请遵循“署名-相同方式共享 4.0 国际 (CC BY-SA 4.0)”协议。