html加载数据,点击加载数据.html

Title

.marginTop{

margin-top: 20px;

}

.box{

width:600px;

height: 300px;

text-align: left;

/*display: flex;*/

/*justify-content: center;*/

background: lightskyblue;

overflow: auto;

}

.box>div{

width: 100%;

box-sizing: border-box;

padding: 10px;

background: greenyellow;

}

.onshow{

background: red !important;

color: white;

}

点击加载数据

{{item.content}}
{{item.time}}

var vm=new Vue({

el:'#app',

data:{

list:'',

isShow:true

},

methods:{

a1(){

axios.get('./a1.json').then(res=>{

console.log(res)

console.log(res.data.list)

this.list=res.data.list;

// this.isShow=false;

}).catch(err=>{

console.log(err)

})

}

}

})

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的示例代码,演示了如何使用HTML和JavaScript实现图片的懒: ```html <!DOCTYPE html> <html> <head> <title>Lazy Load Images</title> <style> img { display: block; margin: 10px auto; width: 300px; height: 200px; object-fit: cover; } </style> </head> <body> <h1>Lazy Load Images Example</h1> <div id="imageContainer"> <img data-src="image1.jpg" alt="Image 1"> <img data-src="image2.jpg" alt="Image 2"> <img data-src="image3.jpg" alt="Image 3"> <img data-src="image4.jpg" alt="Image 4"> <img data-src="image5.jpg" alt="Image 5"> </div> <script> function lazyLoad() { const images = document.querySelectorAll('img[data-src]'); images.forEach(img => { if (img.getBoundingClientRect().top <= window.innerHeight && img.getBoundingClientRect().bottom >= 0 && getComputedStyle(img).display !== 'none') { img.src = img.dataset.src; img.removeAttribute('data-src'); } }); } document.addEventListener('DOMContentLoaded', lazyLoad); window.addEventListener('scroll', lazyLoad); </script> </body> </html> ``` 这段代码使用了`data-src`属性来保存图片的实际URL。在页面和滚动事件中,通过检查图片是否在可视区域内来判断是否图片。如果图片在可视区域内,就将`data-src`属性的值赋给`src`属性,并移除`data-src`属性,以图片。 请注意,这只是一个简单的示例代码,实际的懒实现可能需要更多的细节和优化,例如添占位符、处理窗口大小改变等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值