的author's blog有這個例子:
myImage = $('#myImage');
dominantColor = getDominantColor(myImage);
paletteArray = createPalette(myImage, 10); // 2nd argument sets # of colors in palette
文章是舊的,所以代碼不再是相同的,但我認爲sourceImage
在你的例子是一樣的在這種情況下myImage
。
另外,從演示的代碼:
$('.run-functions-button').on('click', function(event) {
var $this = $(this);
$this.text('...');
var $imageSection = $this.closest('.image-section');
var $colorThiefOutput = $imageSection.find('.color-thief-output');
var $targetimage = $imageSection.find('.target-image');
showColorsForImage($targetimage, $imageSection);
});
.run-functions-button
是 「TAP」 黃色按鈕。 它檢索關閉image-section
和target-image
裏面。然後它叫showColorsForImage($targetImage, $imageSection)
。
在showColorsForImage
有這一行:
colorThief.getColor(image)
。所以我很確定這是一個圖像對象,正如Frèdèric在他的評論中已經指出的那樣。
從插件的源代碼,它只是一個[Image](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement)實例。 –
你可能剛剛嘗試過... – ZiNNED
你有沒有試過它看到它的作用?嘗試之前嘗試嘗試。 –