我正在向return返回生成的 html 的地址发出请求。
请求代码如下所示:
document.addEventListener("DOMContentLoaded", function() {
axios.get("/get-cards")
.then(response => {
document.getElementById("load").remove();
$("#content").html(response.data);
})
.catch(error => {
console.log(`ERROR: ${error}`);
});
});
生成 html 的页面(位于 /get-cards)如下所示:
@foreach($technics as $technic)
<div class="technic-card">
<div class="card-img">
<div style="background-image: url('{{ $technic->img_1 }}'" alt="{{ $technic->name }}">
<div style="background-image: url('{{ $technic->img_2 }}'" alt="{{ $technic->name }}">
<div style="background-image: url('{{ $technic->img_3 }}'" alt="{{ $technic->name }}">
</div>
<div class="card-name">{{ $technic->name }}</div>
<div class="card-type">{{ $technic->type }}</div>
<div class="card-footer">
<div class="card-price">{{ $technic->price }}/час</div>
<div class="card-buy-btn">арендовать</div>
</div>
</div>
@endforeach
我需要一个现成的带有加载图片的 html 来添加到页面中,但是会出现以下情况。
- 加载页面,从该页面发送请求,然后将响应发送到该页面(html标记)并添加
- 加载指示灯亮
- 请求返回响应
- 加载指示器已移除
- 将html代码添加到页面
- 和图片开始加载 它看起来像这样
我怎样才能让加载指示器在图片加载之前不会消失?
您需要找到所有图片并等待它们加载的那一刻
在示例中,为方便起见,我将图像的 url 放在了单独的属性中,但很可能
element.style得到您还可以使用waitForImages插件