MiniX自绘渲染跨平台框架
  • 框架说明
  • 声明式开发范式
  • 内置Api
指南
接口
  • Minix CLI
示例
  • 类Web框架

    • 框架说明
    • 类Web开发范式
    • 内置Api
  • 指南
  • 组件
  • 接口
  • 示例
  • 规范
  • DophinHybrid

    • 快速上手 (opens new window)
    • UI 组件库 (opens new window)
    • jsBridge 接口 (opens new window)
  • DolphinWeex

    • 快速上手 (opens new window)
    • UI 组件库 (opens new window)
    • jsBridge 接口 (opens new window)
  • 发布消息
  • 常见问题
  • 更新日志
  • 框架说明
  • 声明式开发范式
  • 内置Api
指南
接口
  • Minix CLI
示例
  • 类Web框架

    • 框架说明
    • 类Web开发范式
    • 内置Api
  • 指南
  • 组件
  • 接口
  • 示例
  • 规范
  • DophinHybrid

    • 快速上手 (opens new window)
    • UI 组件库 (opens new window)
    • jsBridge 接口 (opens new window)
  • DolphinWeex

    • 快速上手 (opens new window)
    • UI 组件库 (opens new window)
    • jsBridge 接口 (opens new window)
  • 发布消息
  • 常见问题
  • 更新日志

# CanvasGradient对象

说明: 从API version 4开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

渐变对象。

# addColorStop

addColorStop(offset: number, color: string): void

设置渐变断点值,包括偏移和颜色。

参数:

参数 类型 描述
offset number 设置渐变点距离起点的位置占总体长度的比例,范围为0到1。
color string 设置渐变的颜色。

示例:

<!-- xxx.mxl -->
<div>
<canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
<input type="button" style="width: 180px; height: 60px;" value="fillStyle"onclick="handleClick" />
</div>
1
2
3
4
5
// xxx.js
export default {
handleClick() {
  const el =this.$refs.canvas;
  const ctx =el.getContext('2d');
  const gradient = ctx.createLinearGradient(0,0,100,0);
  gradient.addColorStop(0,'#00ffff');
  gradient.addColorStop(1,'#ffff00');
}
}
1
2
3
4
5
6
7
8
9
10

zh-cn_image_0000001152610806