staskobzar / vue-audio-visual

VueJS audio visualization components
MIT License
717 stars 112 forks source link

Canvas 100% width #30

Closed agustinbus closed 4 years ago

agustinbus commented 4 years ago

How can i fit canvas to parent div width?

staskobzar commented 4 years ago

canvas is not an auto-scalable element, afak. You can try to detect your parent div's dimensions and set plugin's component property canv-width.

agustinbus commented 4 years ago

I tried it, but not effect using clientWidth. I have a data variable waveWidth, and a div element with waveWidth ref attribute. This is my code:

<av-line ref-link="player" :canv-width="waveWidth"/>

...

mounted() {
   this.waveWidth = this.$refs.recorderCard.clientWidth
}
staskobzar commented 4 years ago

may be recorderCard.clientWidth is not ready in the moment and av-line is using default value. Try conditional render to see if it works:

<av-line v-if="waveWidth > 0" ref-link="player" :canv-width="waveWidth"/>

waveWidth must be observable, reactive parameter

agustinbus commented 4 years ago

It worked! Thanks a lot.

staskobzar commented 4 years ago

welcome