当前位置: 首页 > news >正文

关键词挖掘查询工具爱站网交互式网站定义

关键词挖掘查询工具爱站网,交互式网站定义,长沙公司网站费用,东莞市网络seo推广怎么样vue之封装tab类组件 vue之封装tab类组件CSS样式方面JS方面 vue之封装tab类组件 需求&#xff1a;点击【上一步】、【下一步】按钮&#xff0c;切换tab&#xff0c;且有淡入浅出的动画。 CSS样式方面 <div class"parent"><div class"childDiv" id…

vue之封装tab类组件

    • vue之封装tab类组件
      • CSS样式方面
      • JS方面

vue之封装tab类组件

需求:点击【上一步】、【下一步】按钮,切换tab,且有淡入浅出的动画。

CSS样式方面

<div class="parent"><div class="childDiv" id="div0">0</div><div class="childDiv" id="div1">1</div><div class="childDiv" id="div2">2</div><div class="childDiv" id="div3">3</div><div class="childDiv" id="div4">4</div><div class="childDiv" id="div5">5</div><div class="childDiv" id="div6">6</div><div class="childDiv" id="div7">7</div><div class="childDiv" id="div8">8</div><div class="childDiv" id="div9">9</div>
</div><style>
.parent{background:green;width:600px;height:100px;// 设置flex布局,且当子元素撑开父元素的时候显示滚动条。display:flex;overflow-y: auto;
}.childDiv{background:red;width:200px;height:100px;border:1px solid black;// 此时,让div保持原有宽度,撑开父元素后,出现滚动条,而不是改变宽度自适应。flex-shrink: 0;
}
</style>

JS方面

<div id="myDiv1">需求:点击切换数组中的item,且添加动画</div>
<div id="before" style="margin-top:50px"> 上一个 </div>
<div style="background:green;width:600px;height:100px;display:flex;overflow-y: auto;" id="myDiv2"><div class="childDiv" id="div0">0</div><div class="childDiv" id="div1">1</div><div class="childDiv" id="div2">2</div><div class="childDiv" id="div3">3</div><div class="childDiv" id="div4">4</div><div class="childDiv" id="div5">5</div><div class="childDiv" id="div6">6</div><div class="childDiv" id="div7">7</div><div class="childDiv" id="div8">8</div><div class="childDiv" id="div9">9</div>
</div>
<div id="after" style="margin-top:20px"> 下一个 </div>	
<style>
.coup-anim {/* 淡入 */animation: fadeIn 4s .1s ease both;
}@keyframes fadeIn {0% {opacity: 0;transform: translateY(400upx)}100% {opacity: 1;transform: translateY(0)}
}.childDiv{background:red;width:200px;height:100px;border:1px solid black;flex-shrink: 0;
}
</style>
<script>
// 声明一个变量,用于记载tab总长度
var total = 10;
// 声明一个变量,用于记录移动到那个位置了
var arrIndex = 0;
// 声明一个变量,用于记录移动的步长
var arrStrp = 3;// 一次性移动三个,且添加动画 
var myDiv2 = document.getElementById("myDiv2");var before = document.getElementById("before");
before.addEventListener("click", function() {/*动画方面注释:先移除动画,后添加动画。注意动画需要延迟触发,否则触发不了*/// 移除动画myDiv2.classList.remove("coup-anim");// 延迟触发动画,否则动画触发不了setTimeout(()=>{myDiv2.classList.add("coup-anim");},10)/*重置dispaly的状态*/ for(let i=0;i<=total-1;i++){const divI = document.getElementById("div"+i);divI.style.display = ""}/*正常情况,每次按照步长往前走但是当arrIndex-arrStrp<=0时,也就是再减减不动的时候,只显示前三个。且arrIndex置成0;*/// before操作的时候,arrIndex就是下标的位置。if(arrIndex-arrStrp<=0){// 只显示前面三个,别的div给隐藏掉	for(let i=3;i<total;i++){const divI = document.getElementById("div"+i);divI.style.display = "none"}	arrIndex = 0;return ;			}else{// 只显示前面三个,别的div给隐藏掉	arrIndex = arrIndex-3;const myStep = arrIndex+3;for(let i=0;i<arrIndex;i++){const divI = document.getElementById("div"+i);divI.style.display = "none"}		for(let i=myStep;i<total;i++){const divI = document.getElementById("div"+i);divI.style.display = "none"}}
});// 逻辑同上
var after = document.getElementById("after");after.addEventListener("click", function() {// 移除动画myDiv2.classList.remove("coup-anim");// 延迟触发动画,否则动画触发不了setTimeout(()=>{myDiv2.classList.add("coup-anim");},10)arrIndex = arrIndex+3; // 3// 重置dispaly的状态for(let i=0;i<=total-1;i++){const divI = document.getElementById("div"+i);divI.style.display = "";}if(arrIndex+arrStrp>=total){// 只显示后面三个for(let i=0;i<total-3;i++){const divI = document.getElementById("div"+i);divI.style.display = "none"}arrIndex = total-arrStrp;return ;}else{const myStep = arrIndex+3;for(let i=arrIndex-1;i>=0;i--){const divI = document.getElementById("div"+i);divI.style.display = "none"}		for(let i=myStep;i<total;i++){const divI = document.getElementById("div"+i);divI.style.display = "none"}	}});
</script>

总的来说是这个思路:

  1. 需要三个确定的数值:(这个是相通的,比如分片上传。需要这些参数,也是为了将数组分片)
    1.1.1 数组的长度(tab长度)
    1.1.2 起始的下标(游标)
    1.1.3 步长
  2. 【上一步】、【下一步】按钮的逻辑
    2.1.1 【下一步】如果说:if(游标arrIndex + 步长arrstep > 数组的长度的时候,说明已经到底了。这个时候,需要显示后面三个,其余的隐藏即可) else(显示游标arrIndex后面的三个元素即可,别的隐藏)
    2.1.2 【上一步】 如果说if(游标arrIndex - 步长arrstep<0 的时候,说明已经到头了。这个时候,只需要显示前面三个,其余的隐藏即可) else(显示游标arrIndex后面的三个元素即可)
  3. 在按钮点击的时候,添加动画。

代码已资源绑定

http://www.sczhlp.com/news/73003/

相关文章:

  • django做的网站安徽建设工程信息网中项网
  • 网站优化软件破解版wordpress大学 视频教程
  • 免费浏览的网站入口wordpress 提示插件
  • 如何建网站费用多少大连装修公司哪家比较好
  • 网站导航栏目焦点设置网站 形象入口页
  • 做网站有什么框架百度生成手机网站
  • 网站建设及维护服务技术指标张家口万全区建设网站
  • 部门网站建设情况汇报中国企业排名前十
  • 一诺互联网站建设公司wordpress自定义右键
  • 网站制作上网清新太和做网站
  • 网站后缀ccwordpress糗事百科
  • git操作详解
  • 如何自己做购物网站网站建设需要什么材料
  • 比较还做的调查网站wordpress编辑远程图片大小
  • wordpress网站定制c语言和c 哪个做网站好
  • 新余百度网站建设英选 网站开发
  • 西安个人网站建设龙岩天宫山有几个台阶
  • 修改Linux终端用户名的颜色
  • 网站搭建原则廊坊首页霸屏排名优化
  • 网站因为备案关闭了 怎么办网站开发教材
  • 网站开发需求分析报告python+视频播放网站开发
  • 萧山城市建设网站南通高端网站建设公司
  • 编程网站scratch科技进步是国防强大的重要的保证
  • 中期通网站建设wordpress 视频 主题
  • 长沙做网站公司哪家好湖北省建设厅网站证件
  • 山西省城乡住房和建设厅网站首页移动网站设计教程
  • 专注网站建设与制作怎么套用模板做网站
  • 网站建设步奏软件公司怎么找客户
  • 网站开发公司加盟百度指数三个功能模块
  • 免费的网站源码去哪下载网站开发技术总结报告