I have a div with a flexattribute and I'm scaling down its content dynamically using Vue. However, the parent div's height remains the same as it was originally.

<template>
    <div style="width: 100%; overflow: hidden; display: flex; flex: 1 1 auto;">
        <slot ref="target" :scale="scale"></slot>
    </div>
</template>

<script>
    export default {
      data () {
        return {
          scale: 1,
          initialWidth: null
        }
      },

      mounted () {
        this.calculateScale()

        let vm = this
        this.$nextTick(function () {
          window.addEventListener('resize', vm.calculateScale);
        })
      },

      methods: {
        calculateScale () {
          let content = $(this.$el).children()[0]

          if (!this.initialWidth) {
            this.initialWidth = $(content).width()
          }

          let containerWidth = $(this.$el).width()

          console.log(containerWidth + ' ' + this.initialWidth)

          this.scale = containerWidth / this.initialWidth
        },
      }
    }
</script>

Then the code is used like so:

<scale v-if="event.last_action_type === 'ad'">
  <ad-preview slot-scope="{ scale }" :style="'transform: scale(' + scale + '); transform-origin: top left;'" :ad="event.last_action"></ad-preview>
</scale>

I am trying to get the div container fit the content.

0 Answers