img
タグを持つポリマー要素を作成しました。私は基本的にイメージから支配的な色をピックアップし、カラーコードを与えるjavascriptライブラリ(Vibrant.js)を使用しています。私はポリマーのattached
イベントでイメージ要素を選択しようとしています。しかし、どういうわけか、イメージ要素が適切に選択されていません。ポリマー要素の荷重でimg要素を選択
次の例外があります。
Vibrant.min.js:1 Uncaught IndexSizeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0.
<dom-module id="my-image-block">
<template>
<div class="service-wrapper">
<div><img id="imgobject" src={{imagepath}}></div>
<div class="service-wrapper-inner">
<div>
<p class="group-title">Stencil
<p> <!--TODO : Remove hard coding-->
<div class="title">
<p>Some content</p></div>
<p class="last-modified">Last updated: {{lastmodified}}</p>
</div>
<div class="description">
<p>{{description}}</p>
</div>
</div>
</div>
</template>
<script>
Polymer({
is: "my-image-block",
attached: function() {
var self = this;
var imageobject = self.$.imgobject;
var vibrant = new Vibrant(imageobject, 64, 6);
var swatches = vibrant.swatches();
var backColor = swatches["Vibrant"].getHex()
$(".service-wrapper-inner").css("background-color", backColor);
}
});
</script>
ポリマーに問題はありません。コンソールに 'imageobject'を記録すると、有効なオブジェクトを見ることができるはずです – a1626