やりたいこと (1-3 を達成した):
- ページから画像を取得する
- キャンバス要素に追加します
- 画像をマスクにクリップする
- 画像の周りでマスクを移動 (アニメーション)
最初の 3 つを達成しましたが、マスクの移動方法がわかりません。助けてください!
// get the canvas
var canvas = document.getElementById('c');
var context = canvas.getContext('2d');
// get a div from the page
var stuff = document.getElementsByName('testElem')[0];
// add a class to the div
stuff.setAttribute('class', 'pleaseWork');
var newImage = new Image();
// get the background image of the div
var bgClass = document.getElementsByClassName('pleaseWork')[0].style.backgroundImage;
var x = canvas.width / 2;
var y = canvas.height / 2;
var radius = 75;
var offset = 50;
// clip the context to create a circular clipping mask
context.save();
context.beginPath();
context.arc(x, y, radius, 0, 2 * Math.PI, false);
context.clip();
// on load put the image into the clipping mask
newImage.onload = function () {
context.drawImage(newImage,0,0);
}
// put the background image from the div into the canvas (without the url())
newImage.src = bgClass.replace(/^url|[\(\)]/g, '');
キャンバスからクリッピング マスクを移動 (アニメーション化) して、クリッピングされた画像のさまざまな部分を表示するにはどうすればよいですか?
アイデアをありがとう!