首页轮播切换效果demo

效果图:

 主页面:

<script setup lang="ts">
import { Swiper, SwiperSlide } from 'swiper/vue'
import { Mousewheel, Keyboard } from 'swiper'
import { ref } from 'vue'

// Import Swiper styles
import 'swiper/css'
import 'swiper/css/navigation'
import 'swiper/css/pagination'
import 'swiper/css/scrollbar'
import Comp from './comp.vue'
const modules = ref([Mousewheel, Keyboard])
const color = ['#ce1111', '#008cff', '#0ab86f', '#d37a07', '#76a30c']
const curSlide = ref(0)
const slideChange = (swiper) => {
  curSlide.value = swiper.activeIndex
}
</script>

<template>
  <div class="head" :class="curSlide !== 0 && 'affix'">头部</div>

  <div class="swiper-home">
    <swiper
      direction="vertical"
      :mousewheel="true"
      :keyboard="{
        enabled: true
      }"
      @slide-change-transition-start="slideChange"
      slides-per-view="auto"
      :modules="modules"
      class="h-swiper"
    >
      <swiper-slide class="m-slide" v-for="(item, i) in color" :key="i">
        <div :style="{ background: item }" class="slide-item">
          <Comp v-show="curSlide === i" />
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<style lang="scss" scoped>
.head {
  background: lightblue;
  text-align: center;
  font-size: 30px;
  position: fixed;
  top: 0;
  left: 0;
  height: 100px;
  width: 100%;
  z-index: 99;
  &.affix {
    background-color: white;
  }
}
.swiper-home {
  width: 100%;
  height: 100%;
}

.h-swiper {
  width: 100%;
  height: 100%;

  .m-slide {
    height: 100%;
    width: 100%;
    .slide-item {
      display: flex;
      font-size: 40px;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
    }

    &:last-child {
      height: 200px !important;
    }
  }
}
</style>

comp.vue

<script setup lang="ts"></script>

<template>
  <div class="test">fffffff</div>
</template>

<style lang="scss" scoped>
.test {
  animation: fadeinR 1s forwards;
}

@keyframes fadeinR {
  0% {
    opacity: 0;
    transform: translateX(1000px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
WPF(Windows Presentation Foundation)是一种用于创建Windows桌面应用程序的技术框架,可以实现丰富的用户界面和交互效果。图片轮播切换动画是在WPF中常见的一个功能,可以使图片在切换时产生平滑的过渡效果。 要实现WPF图片轮播切换动画,可以按照以下步骤进行: 1. 创建一个WPF窗体或用户控件,用于显示图片和进行动画效果切换。 2. 在界面中添加一个Image控件,用于显示图片。可以通过设置Image的Source属性来加载要显示的图片。 3. 创建一个Storyboard对象,用于定义轮播切换的动画效果。可以使用WPF内置的动画效果,如Fade(淡入淡出)、Slide(滑动)等。根据需求调整动画的速度、延迟等属性。 4. 将动画效果添加到Storyboard中,并关联到Image控件的相关属性。例如,通过使用DoubleAnimation anim1 = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(1))来定义一个从0到1的透明度变化动画效果,然后将其关联到Image的Opacity属性。 5. 创建一个Timer(计时器)对象,用于定时触发图片切换的动画效果。可以使用DispatcherTimer类来实现,设置时间间隔和Tick事件。 6. 在Timer的Tick事件中,根据需要切换要显示的图片。可以通过修改Image的Source属性来加载不同的图片。 7. 在Timer的Tick事件中,启动Storyboard开始动画效果的播放。可以调用Storyboard的Begin方法来启动。 8. 重复步骤6和7,实现图片轮播切换效果。可以根据实际需求设定切换的频率和图片的数量。 通过以上步骤,就可以实现WPF图片轮播切换动画效果。可以根据实际需求调整动画效果的参数,如切换速度、图片大小、切换方式等,使得界面显示出更加美观和吸引人的效果
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值