E
E
Eugene2020-01-23 01:05:21
Vue.js
Eugene, 2020-01-23 01:05:21

How to dynamically resize a block?

I'm trying to implement block resizing when scrolling the mouse wheel. When inspecting the element, I see that the transform property changes, but visually the block doesn't change.
https://jsfiddle.net/eo9L1452/

<div 
        class="workspase" 
        id="workspase" 
        @mousewheel.passive="handleZoom($event)"
>
            <div 
                style="width: 100px; height: 100px; background: red;" 
                :transform="computedMatrix"
            ></div>
</div>

export default {
    data () {
        return {
            matrix: { a: 1, b: 0, c: 0, d: 1, x: 0, y: 0 },
            zoom: 1,
        }
    },
    computed: {
        computedMatrix () {
            const { a, b, c, d, x, y } = this.matrix
            return `matrix(${this.zoom}, ${b}, ${c}, ${this.zoom}, ${x}, ${y})`
        },
    },
    methods: {
        handleZoom ({ deltaY }) {
            this.zoom = deltaY < 0 ? (this.zoom * 10 + 1) / 10 : (this.zoom * 10 - 1) / 10
        },
        
    },
}

.workspase {
        width: 800px;
        height: 500px;
        border: 2px solid black;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-01-23
@you_are_enot

There is no such attribute - transform. This should be the style property:
:style="{ transform: computedMatrix }"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question