首页 > 其他分享 >手风琴、轮播图案例

手风琴、轮播图案例

时间:2024-10-16 17:52:43浏览次数:3  
标签:轮播 clip nth photo li 案例 path 手风琴 div

摸鱼时,水一篇博客咯~~~分享两个小案例!!!!!!!!!!!!


前言

手风琴:仿王者荣耀做的一个小案例,结合JQuery.js

轮播图:仿华泰保险官网首页图做的小案例,结合ant-design-vue轮播图使用


一、手风琴

  • 效果图

  • 代码
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    ul {
      height: 150px;
      /* width: 1500px; */
      display: flex;
    }
    ul li {
      list-style: none;
      position: relative;
      height: 134px;
      cursor: pointer;
    }
    ul li>div {
      display: inline-block;
      width: 134px;
      height: 134px;
    }
    ul li>img {
      display: inline-block;
      width: 291px;
      height: 134px;
    }
    ul li:nth-child(1)>div {
      background: url(./imgs/1b.jpg) no-repeat right 0;
    }
    ul li:nth-child(2)>div {
      background: url(./imgs/2b.png) no-repeat right 0;
    }
    ul li:nth-child(3)>div {
      background: url('./imgs/3b.jpg') no-repeat right 0;
    }
    ul li:nth-child(4)>div {
      background: url('./imgs/4b.png') no-repeat right 0;
    }
    li div {
      position: absolute;
      left: 0;
      top: 0;
    }
    /* 控制隐藏 */
    ul li:nth-child(1) {
      width: 291px;
      div {
        display: none;
      }
    }
    ul li:nth-child(n+2){
      width: 134px;
      img {
        display: none;
      }
    }
  </style>
</head>
<body>
  <ul>
    <li>
      <div></div>
      <img src="./imgs/1b.jpg" alt="" srcset="">
    </li>
    <li>
      <div></div>
      <img src="./imgs/2b.png" alt="" srcset="">
    </li>
    <li>
      <div></div>
      <img src="./imgs/3b.jpg" alt="" srcset="">
    </li>
    <li>
      <div></div>
      <img src="./imgs/4b.png" alt="" srcset="">
    </li>
  </ul>
  <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
  <script type="text/javascript">
    $(function() {
      $("ul li").mouseenter(function() {
        // 当前li变宽,小图淡出,大图淡入
        $(this).stop().animate({
          width: 291
        }, 200).find("div").stop().fadeOut().siblings("img").stop().fadeIn()
        $(this).siblings("li").stop().animate({
          width: 134
        }, 200).find("img").stop().fadeOut().siblings("div").stop().fadeIn()
      })
    })
  </script>
</body>
</html>

二、轮播图

  • 效果图(注:文中代码只将每张图片切成竖条逐个展示,竖条图片未再切成一小块一小块的!!!)

华泰保险效果图

本文效果图

  • 代码

html:

<a-carousel ref="swiperPic" effect="fade" autoplay v-if="bannerList!=null" :beforeChange="beforeChange">
      <div v-for="(item, index) in bannerList" :key="item.id" class="photo"
        :style="{height: imgHeight+'px', }"
      >
        <img class="logoJH photo-clip" :class="currentPic === index?'down-enter-one':''"  :src="(item.image)" alt="">
        <img class="logoJH photo-clip" :class="currentPic === index?'down-enter-two':''"  :src="(item.image)" alt="">
        <img class="logoJH photo-clip" :class="currentPic === index?'down-enter-three':''"  :src="(item.image)" alt="">
        <img class="logoJH photo-clip" :class="currentPic === index?'down-enter-four':''"  :src="(item.image)" alt="">
        <img class="logoJH photo-clip" :class="currentPic === index?'down-enter-five':''"  :src="(item.image)" alt="">
        <img class="logoJH photo-clip" :class="currentPic === index?'down-enter-six':''"  :src="(item.image)" alt="">
        <img class="bgImg" :src="(bannerList[oldPic].image)" alt="">
      </div>
</a-carousel>

js:

data() {
	return {
              screenWidth: document.body.clientWidth,
         currentPic: 0,
         oldPic: 0,
         bannerList:[{image: '图片地址', id: ''}, {}, ...],
	}
}

mounted() {
    const that = this
    window.onresize = () => {
      return (() => {
        that.screenWidth = document.body.clientWidth
        // console.log(that.screenWidth)
      })()
    }
},
watch: {
    screenWidth(val) {
      // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
      if (!this.timer) {
        this.screenWidth = val
        this.timer = true
        let that = this
        setTimeout(function() {
          // console.log(that.screenWidth)
          // that.imgHeight = 672/2114*Number(that.screenWidth)
          that.timer = false
        }, 400)
      }
    },
    currentPic(n, o) {
      this.oldPic = o
    }
},
computed: {
    imgHeight() {
      let num = 672/2114*Number(this.screenWidth)
      return num
    }
},
methods: {
	beforeChange (from, to) {
      this.currentPic = to;
    },
}

css:

.photo .photo-clip:nth-of-type(1) {
/*photo-clip是每一个碎片对应的包裹的div盒子*/
  -webkit-clip-path: inset(0 83.3% 0 0);
  clip-path: inset(0 83.3% 0 0);
}
.photo .photo-clip:nth-of-type(2) {
/*photo-clip是每一个碎片对应的包裹的div盒子*/
  -webkit-clip-path: inset(0 65% 0 16.7%);
  clip-path: inset(0 66.6% 0 16.6%);
}
.photo .photo-clip:nth-of-type(3) {
/*photo-clip是每一个碎片对应的包裹的div盒子*/
  -webkit-clip-path: inset(0 48% 0 34%);
  clip-path: inset(0 50% 0 33.3%);
}
.photo .photo-clip:nth-of-type(4) {
/*photo-clip是每一个碎片对应的包裹的div盒子*/
  -webkit-clip-path: inset(0 33% 0 49.9%);
  clip-path: inset(0 33% 0 49.9%);
}
.photo .photo-clip:nth-of-type(5) {
  -webkit-clip-path: inset(0 16.7% 0 72%);
  clip-path: inset(0 16.6% 0 66.7%);
}
.photo .photo-clip:nth-of-type(6) {
  -webkit-clip-path: inset(0 0 0 83.3%);
  clip-path: inset(0 0 0 83.3%);
}
.photo {
  position: relative;
}
.photo .photo-clip {
  position: absolute;
}
.down-enter-one {
  animation: move 0.3s ease-in reverse;
}
.down-enter-two {
  animation: move 0.5s ease-in reverse;
}
.down-enter-three {
  animation: move 0.7s ease-in reverse;
}
.down-enter-four {
  animation: move 0.8s ease-in reverse;
}
.down-enter-five {
  animation: move 0.9s ease-in reverse;
}
.down-enter-six {
  animation: move 1s ease-in reverse;
}
@keyframes move {
  0% {
    transform: translate(0, 0) scale(1);
  }
  100% {
    transform: translate(50%, 50%) scale(0);
  }
}
.bgImg {
  position: absolute;
  left: 0;
  top: 0;
  z-index: -100;
  opacity: 0.7;
  width: 100%;
}

总结

分享简单的两个小案例,等待放假啦!!!友友们,下一篇分享一个Vue2项目:既可以发布成一个npm包,也可以被部署发布哦;且依赖包利用微前端(无界)可兼容在Vue3项目里。

标签:轮播,clip,nth,photo,li,案例,path,手风琴,div
From: https://blog.csdn.net/qq_44828539/article/details/142872005

相关文章

  • JVM第7篇-性能监控 & JVM性能调优案例
    JVM第7篇-性能监控&JVM性能调优案例性能监控一、JVM监控及诊断工具-命令行篇1.1基础故障处理工具1.1.1jps:虚拟机进程状况工具命令格式使用1.1.2jstat:虚拟机统计信息监视工具命令格式使用1.1.3jinfo:Java配置信息工具命令格式使用1.1.4jmap:Java内存映像分......
  • 网站后台修改模板?公司网站轮播如何修改?
    网站后台修改模板登录后台:使用管理员账号登录网站后台。导航至模板管理:在后台主界面中找到“模板管理”、“主题设置”或类似的选项。选择模板:从模板列表中选择当前使用的模板或想要切换的新模板。编辑模板:进入模板编辑页面,可以对模板的样式、布局等进行调整。......
  • 代码实战-前端-Vue ElementUI 调用摄像头并上传到后端的代码案例
    先上效果图调用摄像头的图片拍照的图片上传文件的效果图查看上传的图片(上传完的图片合并成一个PDF)引入插件--引入组件importCameraImagefrom'@/components/CameraImage/CameraComponets.vue';--放在vue的components中components:{CameraIm......
  • 前端新手教程:HTML、CSS 和 JavaScript 全面详解及实用案例
    一、引言在当今数字化的时代,前端开发扮演着至关重要的角色,它决定了用户与网页和应用程序交互的体验。HTML、CSS和JavaScript作为前端开发的核心技术,分别负责网页的结构、样式和交互。本教程将为前端新手全面深入地介绍HTML、CSS和JavaScript的知识点,并通过实用案例帮助......
  • 【Stable Diffusion案例教程】如何制作3D立体字场景效果
    StableDiffusion是2022年发布的深度学习文本到图像生成模型,它主要用于根据文本的描述产生详细图像,以及在提示词指导下进行图生图的绘图模式。基于开源的优势,SD有着庞大的用户社群,其中又包含着大量的优秀创作者和优质模型。这份完整版的AI绘画全套学习资料已经上传CSDN,......
  • Python实现K近邻算法:面向对象的思路与详细案例解析
    目录Python实现K近邻算法:面向对象的思路与详细案例解析引言一、K近邻算法的基本原理1.1K近邻算法的核心思想1.2距离度量1.3K的选择二、面向对象的KNN实现2.1类设计2.2Python代码实现2.3代码详解三、案例分析3.1案例一:鸢尾花分类问题描述数据准备模型训练与预测......
  • Python实现朴素贝叶斯算法:面向对象的思路与详细案例解析
    目录Python实现朴素贝叶斯算法:面向对象的思路与详细案例解析引言一、朴素贝叶斯算法的基本原理1.1贝叶斯定理1.2朴素假设二、面向对象的朴素贝叶斯实现2.1类设计2.2Python代码实现朴素贝叶斯分类器实现2.3代码详解三、案例分析3.1案例一:鸢尾花分类问题描述数据......
  • 一个案例入门补环境
    此分享只用于学习用途,不作商业用途,若有冒犯,请联系处理反爬前置信息站点:aHR0cDovLzEyMC4yMTEuMTExLjIwNjo4MDkwL3hqendkdC94anp3ZHQvcGFnZXMvaW5mby9wb2xpY3k=接口:/xjzwdt/rest/xmzInfoDeliveryRest/getInfoDeliveryList破解结果预览何谓补环境补环境其实是补浏览器有而Node......
  • CentOS高可用运维案例之---配置bond0
    案例说明:在CentOS7系统下,两个Server之间网卡部署bond0连接测试。系统版本:[root@node201~]#cat/etc/os-releaseNAME="CentOSLinux"VERSION="7(Core)"ID="centos"ID_LIKE="rhelfedora"VERSION_ID="7"PRETTY_NAME="CentOSLinu......
  • 【可白嫖源码】招聘管理系统(案例分析)
    摘 要    本文旨在设计与实现基于Node.js的招聘管理系统,旨在提升招聘流程的效率和便捷性。通过深入研究Node.js在Web开发中的优势和应用,结合招聘管理系统的需求,构建了一个功能强大、易于使用的系统。利用Node.js的非阻塞I/O、事件驱动等特性,实现了系统的高并发处理......