gpt4 book ai didi

css - 使嵌入式列表响应

转载 作者:行者123 更新时间:2023-11-28 08:50:23 27 4
gpt4 key购买 nike

我想问一下是否可以让嵌入式 airnbnb 房源响应式?我正在使用此代码来共享列表:

 <div class="airbnb-embed-frame" data-id="133213" data-view="home" data-hide-price="true" style="max-width:450px;width:100%;min-height:300px;height:100%;margin:auto;"><a href="https://www.airbnb.com/rooms/133213?s=51"><span>View On Airbnb</span></a><a href="https://www.airbnb.com/rooms/133213?s=51" rel="nofollow">1 BR APT + 1 LIVING RM @ SKYWALK CONDO (24th)</a><script async="" src="https://www.airbnb.com/embeddable/airbnb_jssdk"></script></div>

容器是响应式的,但 iframe 的内容不是。它只显示水平和垂直滚动。

最佳答案

我找到了一个解决方法,但不确定它的效果如何。这是一个 codepen .

基本上,我所做的是通过客户端宽度 - 10(对于正确站点的一些边距)除以嵌入的 div 的宽度来计算比例,然后使用它来将其转换为合适的大小并设置原点向左移动以使其居中。

CSS:

.room-container {
display: flex;
flex-flow: row wrap;
}

.room {
width: 450px;
height: 300px;
margin: auto;
}

@media all and (max-width: 500px) {
.room-container {
flex-direction: column;
}

.room {
transform-origin: left;
}
}

JS:

(function () {
const resize = () => {
let rooms = document.getElementsByClassName('room');

for (let room of rooms) {
let scale = (window.innerWidth - 15) / room.offsetWidth;
room.style.transform = 'scale(' + scale + ')';
}
}

window.onload = () => resize();
window.onresize = () => resize();
})();

关于css - 使嵌入式列表响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47130441/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com