【问题标题】:Width versus Height宽度与高度
【发布时间】:2020-07-24 01:52:56
【问题描述】:

我有一张 225x322 的图片,它在那个分区中(背景)

HTML:

<div class="image-info">

        <div class="image-anime"   :style="[window]" ref="image-anime"  style="background: url('<?php echo $itemanime['poster']; ?>')  no-repeat;">
        </div>
    </div>  

我的目标是让 - 宽度取决于高度

我发现纵横比 = 322 / 225 = 1.43111111111

这是我的 js 代码:

var app3 = new Vue({
    el: '#image-anime',
    data: function(){
        return{
            window: {
                height: null,
                width: null,
            }
        }
    },
    mounted() {
        this.$nextTick(function() {
                window.addEventListener('resize', this.getWindowWidth());
                window.addEventListener('resize', this.getWindowHeight());
        })
    },

    computed: {
        windowHeight() {
                return this.getWindowHeight();
        },
        windowWidth() {
                return this.getWindowWidth();
        }
    },

    methods: {
        getWindowWidth(event) {
                console.log('here')
                return document.documentElement.clientWidth;
        },

        getWindowHeight(event) {
                return document.documentElement.clientHeight;
        }
    },
    methods: {
        returnnewvalue(event) {
            this.windowHeight = this.windowWidth * 1.41
        },
        returnvalue2(event) {
           return this.windowHeight
        }
    }
})

我的css:

.image-info{
    display: flex; 
    flex-direction: row;
    justify-content: space-between;

    height: 400px;
    width: 100%; 

    margin-bottom: 30px; 
}
.image-anime{
    display: flex;
    justify-content: space-between;
    flex-direction: column;

    height: 400px;
    width: 280px;

    background-size: 280px 400px !important;


}

没有标签怎么办?

【问题讨论】:

    标签: javascript css vue.js height width


    【解决方案1】:

    有多种选择。

    看看

    How do I auto-resize an image to fit a 'div' container?

    您不需要 javascript 来执行此操作。看看我的代码

    .image{
        height: 400px;
        background-image: url("https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png");
        background-repeat: no-repeat;
        background-size: contain;
    }
    <div class="image">
    </div>

    结果

    【讨论】:

    • 非常感谢你,但我测试了你的解释,发现我的图片没有因为php而变形。但非常感谢你。你是唯一一个试图帮助我的人
    • @Welisio 我明白了。很高兴我能帮助你。如果问题解决了。请将问题标记为已回答!
    猜你喜欢
    • 2011-09-09
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 2015-01-18
    • 2018-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多