實現(xiàn)滾動加載*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;}li,ul{list-style:none;}.container{width:980px;height:600px;margin:0auto;overflow:auto;}.news__item{height:80px;margin-bottom:20px;border:1pxsolid#eee;}1、helloworld2、helloworld3、helloworld4、helloworld5、helloworld6、helloworldvarwrapper=document.querySelector('.container')varcontainer=document.querySelector('.news')wrapper.addEventListener('scroll',function(){varscrollTop=wrapper.scrollTop;if(scrollTop+wrapper.clientHeight>=container.clientHeight){//觸發(fā)加載數(shù)據(jù)loadMore();}});//渲染數(shù)據(jù)functionloadMore(){varcontent='這是數(shù)據(jù)';varnode=document.getElementById('news');//向節(jié)點內(nèi)插入新生成的數(shù)據(jù)varoldContent=node.innerHTML;node.innerHTML=oldContent+content;}上面代碼是一個下拉自動加載數(shù)據(jù)的,主要是加載varcontent='這里面的數(shù)據(jù)';但是我總不能把數(shù)據(jù)寫死吧,我有個data.json的數(shù)據(jù)文件我想把data.json的數(shù)據(jù)加載在varcontent='';中,并且每向下拉一下,就加載一個id的數(shù)據(jù)data.json[{"id":"001","title":"百度","url":"http://www.baidu.com"},{"id":"002","title":"阿里","url":"www.alibaba.com"},{"id":"003","title":"騰訊","url":"www.qq.com"}]這個代碼應(yīng)該如何完善?
如何把json數(shù)據(jù)加載到j(luò)s變量中?
素胚勾勒不出你
2019-05-22 20:41:18