首页 > 其他分享 >双轮播加切换动画效果组件

双轮播加切换动画效果组件

时间:2024-03-12 14:44:49浏览次数:12  
标签:动画 播加 双轮 100% height width background font id

效果如图,结合了一些动画效果和图片背景,组件开发思路:左侧按钮设置定时器为大轮播,下侧按钮设置定时器为小轮播

当轮播到当组的最后一个就 继续大轮播,停掉小轮播,并处理一些特殊情况和翻页情况。 代码已经注释掉引入图片的路径换成背景颜色,可直接运行。

 

<template>
  <div class="centerWrap">
    <!-- 中上 -->
    <div class="centerWrap-top">
      <!-- 文字部分 -->
      <div class="textWrap">
        <span>{{ jarObj.type }}</span>
        <h1 :class="tipsMove ? 'textLight' : ''">{{ jarObj.id }}</h1>
        <p>{{ jarObj.tipsName }}</p>
      </div>
      <div class="rotateBox">
        <!-- 油品切换 -->
        <div class="jarBtnGroup">
          <div
            v-for="item in jarBtnList"
            :key="item.id"
            class="jarBtn"
            :class="jarBtnActive == item.id ? 'jarBtnActive' : ''"
            @click="jarBtnFn(item)"
          >
            <div class="jarBtnLight">
              {{ item.name }}
            </div>
          </div>
        </div>
        <!-- 右侧小标签 -->
        <transition name="el-zoom-in-center">
          <div class="tipsWrap tipsMove" v-if="tipsMove">
            <ul class="tipsBg">
              <li>
                <p>安全容量:</p>
                <span>{{ jarObj.rongliang }}</span>
              </li>
              <li>
                <p>可发量:</p>
                <span>{{ jarObj.kefaliang }}</span>
              </li>
            </ul>
            <ul class="tipsBg">
              <li>
                <p>当前液位:</p>
                <span>{{ jarObj.yewei }}</span>
              </li>
              <li>
                <p>当前温度:</p>
                <span>{{ jarObj.temp }}</span>
              </li>
              <li>
                <p>标准密度:</p>
                <span>{{ jarObj.midu }}</span>
              </li>
            </ul>
          </div>
        </transition>
        <!-- 背景盘子 -->
        <!-- <img class="roateBg" src="@/assets/images/screen/home-jar-pan.png" /> -->
        <!-- --------------中间罐-------------- -->
        <div class="bigBox rotateJar">
          <!-- <img class="bigBoxImg" src="@/assets/images/screen/bigBox.png" /> -->
          <!-- <img
            class="boxPointImg"
            src="@/assets/images/screen/bigBoxPoint.png"
          /> -->
          <jarHomeBox
            :number="jarObj.percen"
            :barEntityColor="['rgba(0,155,255,0.75)', 'rgba(0,155,255,0.75)']"
            :barEntityAfterColor="['#00a2ff', '#00d7ff']"
          ></jarHomeBox>
        </div>
      </div>
    </div>
    <!-- 中下 -->
    <div class="centerWrap-bottom">
      <!-- 罐选择 -->
      <div class="tabsWrap">
        <div
          class="toPage toLeft"
          :class="[toLeft ? 'active' : '']"
          @click="toNext('up')"
        >
          <!-- <i class="iconfont icon-zuo"></i> -->
          《
        </div>
        <div class="tabsCenter">
          <div class="tabsGroup" :style="{ left: '-' + left + '%' }">
            <div
              class="tabsItem"
              :class="tabsItemActive == item.id ? 'tabsItemActive' : ''"
              @click="tabsClickFn(item, index)"
              v-for="(item, index) in tabsList"
              :key="item.id"
            >
              {{ item.id }}
            </div>
          </div>
        </div>
        <div
          class="toPage toRight"
          :class="[toRight ? 'active' : '']"
          @click="toNext('down')"
        >
          <!-- <i class="iconfont icon-you"></i> -->
          》
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import jarHomeBox from "@/components/jarHomeBox.vue"; //油罐组件
export default {
  name: "jarBoxs",
  components: { jarHomeBox },
  props: {},
  data() {
    return {
      //中间油品列表
      jarBtnList: [
        {
          id: 1,
          name: "92#汽油",
          list: [
            {
              id: "G-208-030",
              tipsName: "92#车用汽油(VIB)",
              percen: 37,
              type: "公路发油",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "1935mm",
              temp: "19.4℃",
              midu: "826kg/m³",
            },
            {
              id: "G-203-030",
              tipsName: "92#车用汽油(VIB)",
              percen: 40,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "2035mm",
              temp: "19.4℃",
              midu: "826kg/m³",
            },
            {
              id: "G-104-200",
              tipsName: "92#车用汽油(VIB)",
              percen: 80,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "4035mm",
              temp: "19.4℃",
              midu: "826kg/m³",
            },
          ],
        },
        {
          id: 2,
          name: "95#汽油",
          list: [
            {
              id: "G-204-030",
              tipsName: "95#车用汽油(VIB)",
              percen: 10,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "1035mm",
              temp: "19.4℃",
              midu: "826kg/m³",
            },
            {
              id: "G-105-200",
              tipsName: "95#车用汽油(VIB)",
              percen: 40,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "2035mm",
              temp: "19.4℃",
              midu: "826kg/m³",
            },
          ],
        },
        {
          id: 3,
          name: "98#汽油",
          list: [
            {
              id: "G-207-020",
              tipsName: "98#车用汽油(VIA)(VIB)",
              percen: 78,
              type: "公路发油",
              rongliang: "1652m³",
              kefaliang: "1242.2吨",
              yewei: "1335mm",
              temp: "24.4℃",
              midu: "826kg/m³",
            },
            {
              id: "G-206-020",
              tipsName: "98#车用汽油(VIA)(VIB)",
              percen: 40,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "2035mm",
              temp: "19.4℃",
              midu: "875.1g/m³",
            },
          ],
        },
        {
          id: 4,
          name: "0#柴油",
          list: [
            {
              id: "D-210-050",
              tipsName: "0#车用柴油(VI)",
              percen: 90,
              type: "不动罐",
              rongliang: "1652m³",
              kefaliang: "1242.2吨",
              yewei: "3335mm",
              temp: "24.4℃",
              midu: "826g/m³",
            },
            {
              id: "D-209-030",
              tipsName: "0#车用柴油(VI)",
              percen: 40,
              type: "公路发油",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "2035mm",
              temp: "19.4℃",
              midu: "875.1g/m³",
            },
            {
              id: "D-205-050",
              tipsName: "0#车用柴油(VI)",
              percen: 96,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "4200mm",
              temp: "26.4℃",
              midu: "875.1g/m³",
            },
            {
              id: "D-202-030",
              tipsName: "0#车用柴油(VI)",
              percen: 20,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "1000mm",
              temp: "14.4℃",
              midu: "875.1g/m³",
            },
            {
              id: "D-201-030",
              tipsName: "0#车用柴油(VI)",
              percen: 40,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "2035mm",
              temp: "19.4℃",
              midu: "875.1g/m³",
            },
            {
              id: "D-106-200",
              tipsName: "0#车用柴油(VI)",
              percen: 69,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "3205mm",
              temp: "19.4℃",
              midu: "875.1g/m³",
            },
            {
              id: "D-103-100",
              tipsName: "0#车用柴油(VI)",
              percen: 40,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "2035mm",
              temp: "19.4℃",
              midu: "875.1g/m³",
            },
            {
              id: "D-102-200",
              tipsName: "0#车用柴油(VI)",
              percen: 60,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "3000mm",
              temp: "15.9℃",
              midu: "875.1g/m³",
            },
            {
              id: "D-101-200",
              tipsName: "0#车用柴油(VI)",
              percen: 49,
              type: "不动罐",
              rongliang: "4565m³",
              kefaliang: "1242.2吨",
              yewei: "2035mm",
              temp: "19.4℃",
              midu: "875.1g/m³",
            },
          ],
        },
      ],
      //中部罐名称
      tabsList: [],
      jarObj: {}, //选中的罐内容
      tipsMove: true, //标签动效
      toLeft: false, //上一页
      toRight: false, //下一页
      page: 1, //中间tab页码
      left: 0, //中间tab位置
      tabsItemActive: "", //中间tab点击
      jarBtnActive: 1, //旋转罐按钮
      timer: null, //油品切换定时器
      num: 0, // 索引
      timer2: null, //罐切换定时器
      num2: 0, // 索引
      typeTimer: null, //类型定时器
      typeNum: 0, //类型索引
    };
  },
  watch: {},
  mounted() {
    this.jarBtnFn(this.jarBtnList[0]);
    this.typePlay(); //罐类型轮播
  },
  methods: {
    //中间上部油品选择
    jarBtnFn(val) {
      //清空两个定时器
      clearInterval(this.timer);
      clearInterval(this.timer2);
      this.num = val.id - 1; //大定时器索引
      this.jarBtnActive = val.id; //油品高亮
      this.tabsList = val.list;
      //处理罐上下页高亮显示
      let length = this.tabsList.length;
      if (length < 5) {
        this.toLeft = false;
        this.toRight = false;
      } else {
        this.toLeft = false;
        this.toRight = true;
      }
      //立即执行一次 罐选择
      this.num2 = 0;
      this.page = 1;
      this.left = 0;
      this.tabsClickFn(this.tabsList[this.num2], this.num2);
      this.play2(); //罐选择自动
    },
    //油品切换自动播放
    autoPlay() {
      if (this.num == 3) {
        this.num = 0;
      } else {
        this.num++;
      }
      this.jarBtnFn(this.jarBtnList[this.num]);
    },
    // 油品(大轮播)设置定时器
    play() {
      this.timer = setInterval(this.autoPlay, 5000);
    },
    //罐切换自动播放
    autoPlay2() {
      let length = this.jarBtnList[this.num].list.length;
      if (this.num2 == length - 1) {
        //当轮播到当组的最后一个就 继续大轮播,停掉小轮播
        this.tabsClickFn(this.tabsList[this.num2], this.num2);
        this.num2 = 0;
        this.page = 1;
        this.play(); //大轮播开始
        clearInterval(this.timer2);
      } else if (this.num2 == 0) {
        //轮播第一个时的特殊处理
        this.num2++;
        this.page = 1;
        this.toNext("up");
      } else {
        //处理带翻页的轮播
        if (this.num == 3 && this.num2 > 4) {
          this.toNext("down");
        }
        this.tabsClickFn(this.tabsList[this.num2], this.num2);
        this.num2++;
      }
    },
    // 罐(小轮播)设置定时器
    play2() {
      this.timer2 = setInterval(this.autoPlay2, 4000);
    },
    //罐tab切换
    tabsClickFn(val, index) {
      this.tabsItemActive = val.id;
      this.num2 = index;
      this.jarObj = val;
      this.tipsMove = false;
      //动效延迟
      setTimeout(() => {
        this.tipsMove = true;
      }, 100);
    },
    //上页下页
    toNext(val) {
      let num = 0;
      num = Math.ceil(this.tabsList.length / 5);
      if (val == "up") {
        // 上一页
        if (this.page == 1) {
          this.left = 0;
        } else {
          this.page--;
          this.left = (this.page - 1) * 100;
        }
      } else {
        // 下一页
        if (this.page == num) {
        } else {
          this.page++;
          this.left = (this.page - 1) * 100;
        }
      }
      // 翻页按激活判断
      if (this.tabsList.length < 5) {
        this.toLeft = false;
        this.toRight = false;
      } else {
        if (this.page == num) {
          this.toLeft = true;
          this.toRight = false;
        } else if (this.page == 1) {
          this.toLeft = false;
          this.toRight = true;
        }
      }
    },
    //油品切换自动播放
    typeAutoPlay() {
      if (this.typeNum == 5) {
        this.typeNum = 0;
      } else {
        this.typeNum++;
      }
    },
    // 油品(大轮播)设置定时器
    typePlay() {
      this.typeTimer = setInterval(this.typeAutoPlay, 2000);
    },
  },
  beforeDestroy() {
    clearInterval(this.timer);
    clearInterval(this.timer2);
    clearInterval(this.typeTimer);
  },
};
</script>
<style lang="scss" scoped>
//中间地图
.centerWrap {
  width: calc(44% - 50px);
  height: 100%;
  margin: 0 25px;
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  background: #0242a3;
  // 中上
  .centerWrap-top {
    width: 100%;
    height: 60%;
    position: relative;
    //文字部分
    .textWrap {
      width: 100%;
      position: absolute;
      bottom: 80%;
      left: 0;
      text-align: center;
      span {
        font-size: 20px;
        font-family: Microsoft YaHei;
        font-weight: bold;
        color: #02aeff;
        line-height: 38px;
      }
      h1 {
        font-size: 30px;
        font-family: Microsoft YaHei;
        font-weight: bold;
        color: #ffffff;
        line-height: 30px;
        text-shadow: 0 0 20px RGBA(0, 174, 255, 1);
      }
      p {
        font-size: 15px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #ffffff;
        line-height: 24px;
        opacity: 0.5;
      }
      .textLight {
        animation: textLight 0.3s ease-in-out;
        @keyframes textLight {
          0% {
            color: #ffffffc4;
            text-shadow: 0 0 20px RGBA(0, 0, 0, 0.5);
          }
          100% {
            color: #ffffff;
            text-shadow: 0 0 25px RGBA(0, 174, 255, 1);
          }
        }
      }
    }
    // 罐样式
    .rotateBox {
      width: 100%;
      height: 100%;
      position: relative;
      // 左侧按钮组
      .jarBtnGroup {
        .jarBtn {
          width: 135px;
          height: 40px;
          margin-bottom: 15px;
          box-sizing: border-box;
          line-height: 40px;
          color: #fff;
          font-size: 16px;
          font-weight: 400;
          text-align: center;
          font-family: Microsoft YaHei;
          // background: url("~@/assets/images/screen/home-jar-bar2.png") no-repeat;
          // background-size: 100% 100%;
          background: #2660f3;
          cursor: pointer;
          .jarBtnLight {
            width: 100%;
            height: 100%;
          }
        }
        .jarBtnActive {
          // background: url("~@/assets/images/screen/home-jar-bar1.png") no-repeat;
          // background-size: 100% 100%;
          background: #02aeff;
        }
        .jarBtn:hover {
          .jarBtnLight {
            // background: url("~@/assets/images/screen/home-jar-bar3.png")
            //   no-repeat;
            // background-size: 100% 100%;
            background: #00e4ff;
          }
        }
      }
      // 右侧小标签
      .tipsWrap {
        height: 215px;
        top: 50px;
        right: 30px;
        position: absolute;
        // background: url("~@/assets/images/screen/home-jar-textBg.png") no-repeat;
        // background-size: 100% 100%;
        background: #02aeff;
        padding: 15px 15px;
        box-sizing: border-box;
        overflow: hidden;

        .tipsBg {
          background: RGBA(1, 174, 255, 0.3);
          border-radius: 5px;
          margin-top: 10px;
          padding: 10px;
          box-sizing: border-box;
          li {
            font-size: 14px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            display: flex;
            line-height: 24px;
            p {
              width: 70px;
              color: #aad1f7;
              text-align: right;
            }
            span {
              width: calc(100% - 70px);
              color: #fff;
              text-align: left;
            }
          }
        }
      }
      .tipsMove {
        animation: tipsMove 0.6s ease;
        //变小
        @keyframes tipsMove {
          0% {
            height: 0px;
          }
          100% {
            height: 215px;
          }
        }
      }
      // 底盘图片
      .roateBg {
        width: 660px;
        bottom: -40px;
        height: 60%;
        position: absolute;
        left: calc(50% - 330px);
        z-index: 0;
      }

      //中间罐
      .bigBox {
        width: 200px;
        height: 271px;
        margin-left: -100px;
        position: absolute;
        left: 50%;
        bottom: 64px;
        bottom: 15%;
        z-index: 2;
        background: #00e4ff;
        // 外层罐图片
        .bigBoxImg {
          width: 100%;
          position: absolute;
          z-index: 11;
        }
        // 粒子背景-大罐
        .boxPointImg {
          width: 189px;
          height: 170px;
          position: absolute;
          top: 90px;
          left: 5px;
          z-index: 8;
        }
      }
      .rotateJar {
        .boxPointImg {
          width: 189px;
          height: 170px;
          position: absolute;
          top: 90px;
          left: 5px;
          z-index: 8;
        }
      }
    }
  }
  //油罐状态
  .centerWrap-bottom {
    width: 100%;
    height: 40%;
    position: absolute;
    left: 0;
    bottom: 0;
    .tabsWrap {
      width: 100%;
      height: 35px;
      line-height: 35px;
      margin-bottom: 15px;
      display: flex;
      justify-content: space-between;
      .tabsCenter {
        width: calc(100% - 50px);
        height: 100%;
        position: relative;
        overflow: hidden;
        .tabsGroup {
          width: 2000px;
          height: 100%;
          position: absolute;
          left: 0;
          top: 0;
          transition: left 1s ease;
          .tabsItem {
            width: 137px;
            height: 100%;
            display: inline-block;
            vertical-align: top;
            white-space: nowrap;
            margin: 0 4px;
            // background: url("~@/assets/images/screen/tabsItem.png") no-repeat;
            background: #8389a2;
            background-size: 100% 100%;
            font-size: 18px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            text-align: center;
            color: #ffffff;
            cursor: pointer;
          }
          .tabsItem:hover {
            color: #00e4ff;
          }
          .tabsItemActive {
            // background: url("~@/assets/images/screen/tabsItemActive.png")
            //   no-repeat;
            // background-size: 100% 100%;
            background: #aad1f7;
          }
        }
      }
      .toPage {
        width: 21px;
        height: 35px;
        line-height: 35px;
        cursor: pointer;
        color: #8389a2;
        text-align: center;
        // background: url("~@/assets/images/screen/to.png") no-repeat;
        // background-size: 100% 100%;
        font-size: 14px;
      }
      .toLeft {
        margin-right: 4px;
      }
      .toRight {
        margin-left: 4px;
      }
      .active {
        color: #fff;
      }
    }
  }
}
</style>

 

 

标签:动画,播加,双轮,100%,height,width,background,font,id
From: https://www.cnblogs.com/ruyijiang/p/18068275

相关文章

  • 38. 敌人的动画执行逻辑
    本节目标上节只是把逻辑写好了,为了让游戏看起来更好看,我们需要将敌人的动画也加上去实现动画状态机敌人的状态比较简单,只有站立、加Buff、攻击、受伤、死亡这五种状态各状态之间的转换关系如下站立->加Buff通过skill触发,立刻执行因为是从AnyState出来的,所以不......
  • 通达信支撑压力自动画线主图指标公式源码
    {通达信支撑压力自动画线主图指标公式源码}N:=5;STICKLINE(C>O,O,C,3,1),COLORRED;STICKLINE(C>O,H,C,0,0),COLORRED;STICKLINE(C>O,O,L,0,0),COLORRED;STICKLINE(C<o,o,c,3,1),colorff901e;STICKLINE(C<o,h,o,0,0),colorff901e;STICKLINE(C<o,c,l,0,0),colorff901e;......
  • 36. 人物动画
    人物动画状态机设置变量isParry 是否在防御isSleep 是否正在睡觉isDead 是否已经死亡attack 攻击hit 受伤skill 技能状态stand 站立parry_stand 防御hurt 受伤attack_pillow 攻击sleep 睡眠wake 醒来skill 技能death 死亡状态切换站立状态可以......
  • powerpoint:缩放定位动画
    一,幻灯片缩放定位插入->缩放定位->幻灯片缩放定位:在弹出窗口中,选中目标幻灯片,然后点插入按钮:插入成功:放映时退出:按键盘上的向上箭头或点击幻灯片底部的向上箭头,即可回到原幻灯片页面,如按空格或向右键箭头,则会按目标幻灯片所在位置向后播放:说明:刘宏缔的架构森林......
  • powerpoint: 放大缩小动画
    一,设置放大动画1,选中图片->工具栏动画标签栏下,选中放大/缩小:属性值:设置为400%选中平滑开始、平滑结束触发器:设置为单击:2,使图片放大后位置在屏幕中间选择图片,选择路径动画->直线:把动画的目标位置:红色的圆点,拖动到页面的中间:选中位置动画,计时的开始:设置为:......
  • three.js动画
    旋转立方体functionrenderScene(){cube.rotation.x+=0.02;cube.rotation.y+=0.02;cube.rotation.z+=0.02;requestAnimationFrame(renderScene);stats.update();renderer.render(scene,camera);}renderScene();弹跳球varstep=0;fu......
  • 16. 抽卡动画
    使用DoTween实现抽卡动画卡牌起始位置和大小首先卡牌被抽出来的时候,需要从某个位置开始,并且它的大小要为0让牌一张张进入玩家手里这段代码,就会在delay的时间内,完成所有卡牌缩放和移动的动画在SetCardLayout外面,再使用一个for循环设置延迟时间项目相关代码代码......
  • flutter动画— —显式动画
    常见的显式动画有RotationTransition、FadeTransition、ScaleTransition、SlideTransition、AnimatedIcon。在显示动画中开发者需要创建一个AnimationController,通过AnimationController控制动画的开始、暂停、重置、跳转、倒播等。RotationTransition(旋转动画)、AnimationC......
  • Vue CLI 系列之(十五)过渡与动画
    过渡与动画Vue封装的过渡与动画1.前置知识CSS3动画【2D转换、3D转换、过渡、动画】参考网站:https://www.runoob.com/css3/css3-animations.html<h1v-show="isShow"id="title">显示了</h1><style> h1{ /*通过animation把"donghua"动画捆绑到h1元素,时长:1......
  • 假期vue学习笔记11 动画
    <template>  <divid="root">    <Test/>    <Test2/>    <Test3/>  </div></template><script>importTestfrom'./components/Test.vue'importTest2from'./comp......