Skip to content

wanglin2/simulateCSSBackgroundInCanvas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

simulateCSSBackgroundInCanvas

canvas中模拟cssbackground-sizebackground-positionbackground-repeat三个属性的部分效果。单位仅支持px%

使用

import drawBackgroundImageToCanvas from './index.js'

let width = 500
let height = 500
let img = '/1.jpg'
let canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
drawBackgroundImageToCanvas(ctx, width, height, img, {
  backgroundRepeat: 'repeat-y',
  backgroundSize: '60%',
  backgroundPosition: 'center center'
}, (err) => {
  if (err) {
    // 失败
  } else {
    // 成功
  }
})

About

在canvas中模拟css的background相关样式

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published