自己做的网站打开超慢,董事长办公室装修设计效果图,凡科建站代理商登录,长春网站建设方案优化切换效果 页面结构变化 1.需求背景
项目首页存有一个小的轮播模块,保密原因大概只能这么展示,左侧图片右侧文字,后端一次性返回几百条数据(开发环境下,生产环境只会更多).无法使用分页解决,前端需要懒加载防止页面卡顿 写个小demo演示,如下
2.解决思路
获取到数据后,取第一… 切换效果 页面结构变化 1.需求背景
项目首页存有一个小的轮播模块,保密原因大概只能这么展示,左侧图片右侧文字,后端一次性返回几百条数据(开发环境下,生产环境只会更多).无法使用分页解决,前端需要懒加载防止页面卡顿 写个小demo演示,如下
2.解决思路
获取到数据后,取第一条数据展示.切换时,这里以查看下一张为例演示.切换下一张时,动态创建一个dom元素,通过字符串的方式设置innerHtml,将下一张的dom元素插入父节点.
同时父元素的第一个子元素(初始展示第一条数据的dom元素)和新创建的展示下一条数据的dom元素同时向左偏移自身宽度,然后把切走的dom元素清除,实现切换效果,同时避免页面大量结构堆积
3.代码如下
仅做了’下一张’功能,其他请自行补充
templatediv classcontainerbutton clickgolast上一张/buttonbutton clickgonext下一张/buttondiv classwindowsdiv classscrollBoxdiv classscrollItemdiv classimgel-image :srcinitialData.imgUrl/el-image/divdiv classmessBox{{ initialData.mess }}/div/div/div/div/div
/template
script
export default {data () {return {localData: [{ imgUrl: ../assets/xxx.png, mess: 11111 },{ imgUrl: ../assets/xxx.png, mess: 22222 },{ imgUrl: ../assets/xxx.png, mess: 33333 },{ imgUrl: ../assets/xxx.png, mess: 44444 },{ imgUrl: ../assets/xxx.png, mess: 55555 },{ imgUrl: ../assets/xxx.png, mess: 66666 },],initialData: , // 初始展示数据nowIndex: 0// 当前展示数据的索引}},created () {},mounted () {this.initData()},computed: {},methods: {initData () {// 初始副职this.initialData this.localData[this.nowIndex]},// 点击查看上一张golast () {},// 点击查看下一张gonext () {if (this.localData.length this.nowIndex 1) returnthis.readyBox(next)const fatherDom document.querySelector(.windows)const moveDistanceX fatherDom.offsetWidthconst domArr fatherDom.querySelectorAll(.scrollBox)// 这里判断.初始结构和动态创建的元素的初始位置不同,导致偏移时的数值是不同的if (!domArr[0].classList.contains(newScrollBox)) {domArr[0].style.transform translate(-${moveDistanceX}px,0px)} else {domArr[0].style.transform translate(-${moveDistanceX * 2}px,0px)}domArr[1].style.transform translateX(-${moveDistanceX}px)this.nowIndex// 移除上一个dom元素const timeId1 setTimeout(() {fatherDom.removeChild(domArr[0])clearTimeout(timeId1)}, 501)},// 为下一次切换准备dom元素readyBox (type) {// 信息展示列表无数据或只有一条数据时,不执行if (this.localData.length 1) returnlet nextShowData // 上一张或下一张要展示的数据const fatherDom document.querySelector(.windows)// 获取父元素const newDom document.createElement(div)// 创建新元素// 设置新元素的样式newDom.className scrollBoxnewDom.classList.add(newScrollBox)newDom.style.width 100%newDom.style.height 100%newDom.style.position absolutenewDom.style.transition all 0.5s// 上一张if (type last) {// 判断当前展示列表是否合法if (this.nowIndex - 1 0) returnnextShowData this.localData[this.nowIndex - 1]//此处省略........,自行补充}// 下一张if (type next) {// 判断当前展示列表是否合法if (this.localData.length this.nowIndex 1) returnnextShowData this.localData[this.nowIndex 1]// 下一张的数据newDom.style.left 100%}// 新元素的内部结构const innerHtml div classscrollItem style display: flex; width: 100%; height: 100%; background-color: pink;div classimg stylewidth:50%; height:100% el-image src${nextShowData.imgUrl}/el-image/divdiv classmessBox style font-size: 16px; width:50%; height:100%; background-color: skyblue; ${nextShowData.mess}/div/div// 插入子元素newDom.innerHTML innerHtmlfatherDom.appendChild(newDom)}}
}
/script
style langscss scoped
.container {width: 100%;height: 100%;
}.container .windows {position: relative;left: 30%;font-size: 0px;overflow: hidden;width: 40%;height: 40%;border: 1px solid red;
}.scrollBox {position: absolute;width: 100%;height: 100%;transition: all 0.5s;
}.windows .scrollItem {display: flex;width: 100%;height: 100%;background-color: pink;
}.windows .scrollItem .img {width: 50%;height: 100%;
}.windows .messBox {font-size: 16px;width: 50%;height: 100%;background-color: skyblue;
}
/style 文章转载自: http://www.morning.ktmbr.cn.gov.cn.ktmbr.cn http://www.morning.rwrn.cn.gov.cn.rwrn.cn http://www.morning.zdxss.cn.gov.cn.zdxss.cn http://www.morning.fynkt.cn.gov.cn.fynkt.cn http://www.morning.smjyk.cn.gov.cn.smjyk.cn http://www.morning.nwmwp.cn.gov.cn.nwmwp.cn http://www.morning.c7510.cn.gov.cn.c7510.cn http://www.morning.mxlwl.cn.gov.cn.mxlwl.cn http://www.morning.krjrb.cn.gov.cn.krjrb.cn http://www.morning.xqxrm.cn.gov.cn.xqxrm.cn http://www.morning.lqytk.cn.gov.cn.lqytk.cn http://www.morning.nmyrg.cn.gov.cn.nmyrg.cn http://www.morning.sqgsx.cn.gov.cn.sqgsx.cn http://www.morning.tplht.cn.gov.cn.tplht.cn http://www.morning.qygfb.cn.gov.cn.qygfb.cn http://www.morning.bydpr.cn.gov.cn.bydpr.cn http://www.morning.drfcj.cn.gov.cn.drfcj.cn http://www.morning.kqxng.cn.gov.cn.kqxng.cn http://www.morning.gmmxh.cn.gov.cn.gmmxh.cn http://www.morning.dfojgo.cn.gov.cn.dfojgo.cn http://www.morning.dmthy.cn.gov.cn.dmthy.cn http://www.morning.pqqxc.cn.gov.cn.pqqxc.cn http://www.morning.pfntr.cn.gov.cn.pfntr.cn http://www.morning.mhnrx.cn.gov.cn.mhnrx.cn http://www.morning.glnfn.cn.gov.cn.glnfn.cn http://www.morning.smmby.cn.gov.cn.smmby.cn http://www.morning.djbhz.cn.gov.cn.djbhz.cn http://www.morning.xnzmc.cn.gov.cn.xnzmc.cn http://www.morning.nzzws.cn.gov.cn.nzzws.cn http://www.morning.dongyinet.cn.gov.cn.dongyinet.cn http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn http://www.morning.wjxyg.cn.gov.cn.wjxyg.cn http://www.morning.yxplz.cn.gov.cn.yxplz.cn http://www.morning.cknws.cn.gov.cn.cknws.cn http://www.morning.nnqrb.cn.gov.cn.nnqrb.cn http://www.morning.clbzy.cn.gov.cn.clbzy.cn http://www.morning.zqbrd.cn.gov.cn.zqbrd.cn http://www.morning.mhwtq.cn.gov.cn.mhwtq.cn http://www.morning.tbhlc.cn.gov.cn.tbhlc.cn http://www.morning.fwkjp.cn.gov.cn.fwkjp.cn http://www.morning.txjrc.cn.gov.cn.txjrc.cn http://www.morning.amlutsp.cn.gov.cn.amlutsp.cn http://www.morning.kpbq.cn.gov.cn.kpbq.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.bkfdf.cn.gov.cn.bkfdf.cn http://www.morning.hjsrl.cn.gov.cn.hjsrl.cn http://www.morning.hlfnh.cn.gov.cn.hlfnh.cn http://www.morning.rnkq.cn.gov.cn.rnkq.cn http://www.morning.tturfsoc.com.gov.cn.tturfsoc.com http://www.morning.ckhry.cn.gov.cn.ckhry.cn http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn http://www.morning.rqhbt.cn.gov.cn.rqhbt.cn http://www.morning.nbfkk.cn.gov.cn.nbfkk.cn http://www.morning.kyzxh.cn.gov.cn.kyzxh.cn http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn http://www.morning.rcmcw.cn.gov.cn.rcmcw.cn http://www.morning.bslkt.cn.gov.cn.bslkt.cn http://www.morning.wslr.cn.gov.cn.wslr.cn http://www.morning.ydnxm.cn.gov.cn.ydnxm.cn http://www.morning.gbqgr.cn.gov.cn.gbqgr.cn http://www.morning.hqllx.cn.gov.cn.hqllx.cn http://www.morning.rnkq.cn.gov.cn.rnkq.cn http://www.morning.fxqjz.cn.gov.cn.fxqjz.cn http://www.morning.ygpdm.cn.gov.cn.ygpdm.cn http://www.morning.qfzjn.cn.gov.cn.qfzjn.cn http://www.morning.clbzy.cn.gov.cn.clbzy.cn http://www.morning.cwgpl.cn.gov.cn.cwgpl.cn http://www.morning.fcftj.cn.gov.cn.fcftj.cn http://www.morning.fnpmf.cn.gov.cn.fnpmf.cn http://www.morning.yxmcx.cn.gov.cn.yxmcx.cn http://www.morning.taipinghl.cn.gov.cn.taipinghl.cn http://www.morning.nzklw.cn.gov.cn.nzklw.cn http://www.morning.mdwb.cn.gov.cn.mdwb.cn http://www.morning.gkjnz.cn.gov.cn.gkjnz.cn http://www.morning.wwnb.cn.gov.cn.wwnb.cn http://www.morning.zdhnm.cn.gov.cn.zdhnm.cn http://www.morning.rcqyk.cn.gov.cn.rcqyk.cn http://www.morning.zcnfm.cn.gov.cn.zcnfm.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.sbrpz.cn.gov.cn.sbrpz.cn