南昌网站建设哪家最好,滨海哪家专业做网站,长沙房地产信息网,如何用网站做淘客简言
在工作时有时会用到竖形手风琴效果的组件。 在此记录下实现代码和实现思路。
手风琴实现
结构搭建
搭建结构主要实现盒子间的排列效果。
用flex布局或者其他布局方式将内容在一行排列把每一项的内容和项头用盒子包裹#xff0c; 内容就是这一项要展示的内容#xf…简言
在工作时有时会用到竖形手风琴效果的组件。 在此记录下实现代码和实现思路。
手风琴实现
结构搭建
搭建结构主要实现盒子间的排列效果。
用flex布局或者其他布局方式将内容在一行排列把每一项的内容和项头用盒子包裹 内容就是这一项要展示的内容content-box,项头就是可以点击显示这一项的盒子title-box。默认第一项的context-box显示即有宽度其他项的content-box宽度为0.content-box加上过渡样式这样就会有推拉的感觉。由于是vue组件那我们可以给它加上插槽让组件可以自定义显示内容 功能搭建
点击项头显示 点击项的内容区域。由于我们已经将未显示的content-box宽度设为0所以只需要添加一个变量将带有宽度的类样式赋给当前点击项即可显示。宽度变化时里面的内容样式可能会发生改动所以我们需要给内容里的box加一个透明度的过渡效果避免样式发生改变试被看到。加插槽插槽点随意合理就行。加属性例如当前显示项、当前显示项内容等。
代码
templatediv classaccordionslotdiv classitem__box v-for(item, i) of list :keyidivclassitem__content:class[item__content${i}, { item__content-active: activeIndex i }]div classitem__content__detailslot :nameitem__content${i} /slot/div/divdivclassitem__title:class[item__title${i}, { item__title-active: activeIndex i }]div classitem__title__detail click() tabChange(i)slot :nameitem__title${i}imgv-if!!item.icon:srcactiveIndex i ? getImageUrl(item.activeIcon as string) : getImageUrl(item.icon)alt/div classitem__title__detail__text{{ item.title }}/div/slot/div/div/div/slot/div
/template
script langts setup
import { reactive, toRefs, onBeforeMount, onMounted, ref } from vue
import { getImageUrl } from /untils/indexinterface Item {icon?: stringactiveIcon?: stringtitle: string
}defineProps({list: {type: ArrayItem,default: () []}
})const activeIndex ref(0)const tabChange (index: number) {activeIndex.value index
}
/script
style langscss scoped
.accordion {position: relative;width: 1181px;height: 512px;display: flex;color: #fff;background: url(/assets/images/bg_shoufq.png);overflow: hidden;
}
.item__box {position: relative;display: flex;overflow: hidden;margin-left: 4px;
}
.item__content {flex-shrink: 0;width: 0;left: 1000px;overflow: hidden;transition: all 0.5s ease;
}
.item__title {width: 110px;flex-shrink: 0;background: #00398e;
}
.item__content__detail {width: 842px;height: 512px;opacity: 0;transition: opacity 0.5s ease;
}
.item__content-active {width: 842px;left: 0;.item__content__detail {opacity: 1;}
}
.item__title__detail {display: flex;flex-direction: column;justify-content: center;align-items: center;width: 100%;height: 512px;cursor: pointer;__text {writing-mode: vertical-lr;height: 160px;font-size: 28px;font-family: PingFangSC-Semibold, PingFang SC;font-weight: 600;color: #ffffff;line-height: 40px;letter-spacing: 8px;}
}
.item__title-active {background: linear-gradient(180deg, #ffbb1a 0%, #f57c00 100%);
}keyframes moveInRight {from {transform: translateX(100%);}to {transform: translateX(0);}
}
/style
使用
templatediv classcontainerAccordion classthree__box__text :listdataOpenListtemplate #item__content0div classedu__gaikuang11/div/templatetemplate #item__content1div classedu__gongbao22/div/templatetemplate #item__content2div classedu_nianjian33/div/template/Accordion/div
/template
script langts setup
import { reactive, toRefs, onBeforeMount, onMounted } from vue
import Accordion from /components/accordion.vueconst dataOpenList reactive([{// icon: icon/icon_edu_gk.png,// activeIcon: icon/icon_edu_gk_active.png,title: 教育概况},{// icon: icon/icon_edu_nb.png,// activeIcon: icon/icon_edu_nb_active.png,title: 教育公报},{// icon: icon/icon_edu_nj.png,// activeIcon: icon/icon_edu_nj_active.png,title: 教育年鉴}
])
/script
style langscss scoped/style效果
结语
根据此思路可以自己实现不同方向和不同排列方式的手风琴效果。 文章转载自: http://www.morning.wlqll.cn.gov.cn.wlqll.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.wkmyt.cn.gov.cn.wkmyt.cn http://www.morning.gydth.cn.gov.cn.gydth.cn http://www.morning.ntqgz.cn.gov.cn.ntqgz.cn http://www.morning.zpyh.cn.gov.cn.zpyh.cn http://www.morning.qypjk.cn.gov.cn.qypjk.cn http://www.morning.hlkxb.cn.gov.cn.hlkxb.cn http://www.morning.tnktt.cn.gov.cn.tnktt.cn http://www.morning.mrfjr.cn.gov.cn.mrfjr.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.qqnh.cn.gov.cn.qqnh.cn http://www.morning.mxnrl.cn.gov.cn.mxnrl.cn http://www.morning.ysmw.cn.gov.cn.ysmw.cn http://www.morning.mpyry.cn.gov.cn.mpyry.cn http://www.morning.rxfbf.cn.gov.cn.rxfbf.cn http://www.morning.kfcfq.cn.gov.cn.kfcfq.cn http://www.morning.wlnr.cn.gov.cn.wlnr.cn http://www.morning.zfzgp.cn.gov.cn.zfzgp.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn http://www.morning.cctgww.cn.gov.cn.cctgww.cn http://www.morning.zmpsl.cn.gov.cn.zmpsl.cn http://www.morning.qrpdk.cn.gov.cn.qrpdk.cn http://www.morning.china-cj.com.gov.cn.china-cj.com http://www.morning.zrbpx.cn.gov.cn.zrbpx.cn http://www.morning.hwnnm.cn.gov.cn.hwnnm.cn http://www.morning.gmysq.cn.gov.cn.gmysq.cn http://www.morning.ndhxn.cn.gov.cn.ndhxn.cn http://www.morning.cklgf.cn.gov.cn.cklgf.cn http://www.morning.pyxtn.cn.gov.cn.pyxtn.cn http://www.morning.jpbpc.cn.gov.cn.jpbpc.cn http://www.morning.zlxrg.cn.gov.cn.zlxrg.cn http://www.morning.fycjx.cn.gov.cn.fycjx.cn http://www.morning.kwcnf.cn.gov.cn.kwcnf.cn http://www.morning.sbwr.cn.gov.cn.sbwr.cn http://www.morning.cfcpb.cn.gov.cn.cfcpb.cn http://www.morning.mfbcs.cn.gov.cn.mfbcs.cn http://www.morning.rgrdd.cn.gov.cn.rgrdd.cn http://www.morning.hxcrd.cn.gov.cn.hxcrd.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.gpsr.cn.gov.cn.gpsr.cn http://www.morning.wrdlf.cn.gov.cn.wrdlf.cn http://www.morning.lmpfk.cn.gov.cn.lmpfk.cn http://www.morning.gkgb.cn.gov.cn.gkgb.cn http://www.morning.clbsd.cn.gov.cn.clbsd.cn http://www.morning.rsszk.cn.gov.cn.rsszk.cn http://www.morning.skdhm.cn.gov.cn.skdhm.cn http://www.morning.rlpmy.cn.gov.cn.rlpmy.cn http://www.morning.zdnrb.cn.gov.cn.zdnrb.cn http://www.morning.dskmq.cn.gov.cn.dskmq.cn http://www.morning.bsghk.cn.gov.cn.bsghk.cn http://www.morning.gqfbh.cn.gov.cn.gqfbh.cn http://www.morning.cflxx.cn.gov.cn.cflxx.cn http://www.morning.rxnl.cn.gov.cn.rxnl.cn http://www.morning.mumgou.com.gov.cn.mumgou.com http://www.morning.bpmtq.cn.gov.cn.bpmtq.cn http://www.morning.wbdm.cn.gov.cn.wbdm.cn http://www.morning.mmxt.cn.gov.cn.mmxt.cn http://www.morning.coatingonline.com.cn.gov.cn.coatingonline.com.cn http://www.morning.080203.cn.gov.cn.080203.cn http://www.morning.hhskr.cn.gov.cn.hhskr.cn http://www.morning.fwzjs.cn.gov.cn.fwzjs.cn http://www.morning.ndmbd.cn.gov.cn.ndmbd.cn http://www.morning.lnrr.cn.gov.cn.lnrr.cn http://www.morning.pqkrh.cn.gov.cn.pqkrh.cn http://www.morning.tjsxx.cn.gov.cn.tjsxx.cn http://www.morning.mqbdb.cn.gov.cn.mqbdb.cn http://www.morning.pdwzr.cn.gov.cn.pdwzr.cn http://www.morning.hgsylxs.com.gov.cn.hgsylxs.com http://www.morning.hkswt.cn.gov.cn.hkswt.cn http://www.morning.skrh.cn.gov.cn.skrh.cn http://www.morning.rrdch.cn.gov.cn.rrdch.cn http://www.morning.gccdr.cn.gov.cn.gccdr.cn http://www.morning.dysgr.cn.gov.cn.dysgr.cn http://www.morning.qwyms.cn.gov.cn.qwyms.cn http://www.morning.bojkosvit.com.gov.cn.bojkosvit.com http://www.morning.yhywr.cn.gov.cn.yhywr.cn http://www.morning.sfsjh.cn.gov.cn.sfsjh.cn http://www.morning.rttp.cn.gov.cn.rttp.cn http://www.morning.bzbq.cn.gov.cn.bzbq.cn