国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

改造微信小程序Swiper組件,自定義切換動畫

這篇具有很好參考價值的文章主要介紹了改造微信小程序Swiper組件,自定義切換動畫。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

index.tsx

import { FC, memo, PropsWithChildren, useEffect, useState, useRef, useMemo } from 'react'
import { Swiper as BaseSwiper, SwiperItem, View } from '@tarojs/components'
import { Button } from '@wmeimob/taro-design'
import classNames from 'classnames'
import styles from './index.module.less'
import Taro from '@tarojs/taro'
import { Flex } from '~/components'
import { vibrateShort } from '~/utils/util'
import { SwiperProps } from './const'
// import { getBarHeight } from '~/pages/service/util'

/**
 * Swiper
 * @param props
 * @returns
 */
const Component: FC<PropsWithChildren<SwiperProps>> = ({ current, modes, isDot, onMode, children }) => {
  const [currentIndex, setCurrentIndex] = useState(current ?? 0)
  // const [dx, setDx] = useState(0)
  const currentRef = useRef<number>(0)

  useEffect(() => {
    setCurrentIndex(current)
    return () => {
      Taro.setStorageSync('U1_LASTTIME_MODE_CURRENT', currentRef.current)
    }
  }, [current])
 
  // const getScale = useMemo(() => {
  //   const { windowWidth } = Taro.getSystemInfoSync()
  //   return Math.min(Math.max(dx / (windowWidth - 20), 0.88), 1)
  // }, [dx])
  // console.log('Taro', Taro.getSystemInfoSync().windowWidth, getScale)

  return (
    <View className={styles.container}>
      <BaseSwiper
        // autoplay
        // interval={2500}
        easingFunction='easeOutCubic'
        circular
        duration={1000}
        previousMargin='8px'
        nextMargin='12px'
        current={currentIndex}
        className={styles.swiperBox}
        onChange={(event) => {
          setCurrentIndex(event.detail.current)
          currentRef.current = event.detail.current
          vibrateShort()
        }}
        // style={{
        //   height: Taro.getSystemInfoSync().windowHeight - getBarHeight() - 44 - 34
        // }}
        // onTransition={(event) => {
        //   console.log('onTransition', event.detail.dx)
        //   setDx(event.detail.dx)
        // }}
      >
        {modes.map((mode, index) => {
          return (
            <SwiperItem key={`key-${index}`}>
              <Flex
                column
                style={{
                  backgroundImage: `url(${mode?.bgImg})`
                  // transform: index === currentIndex ? ` scale(${getScale})` : undefined
                }}
                className={classNames(styles.swiperItem,{
                  [styles.swiperItemActive]: index === currentIndex,
                  [styles.swiperItemOutRight]: index > currentIndex,
                  [styles.swiperItemOutLeft]: index < currentIndex
                })}
              >
                <Button
                    className={styles.button}
                    type="main"
                    text='開始護膚'
                    onClick={(event) => {
                      event.stopPropagation()
                      onMode?.(mode)
                    }}
                   />
              </Flex>
            </SwiperItem>
          )
        })}
      </BaseSwiper>
      {isDot && (
        <Flex alignCenter className={styles.dots}>
          {modes.map((_, index) => {
            return (
              <View
                key={`key-${index}`}
                className={classNames(styles.dot, {
                  [styles.dotActive]: index === currentIndex
                })}
              />
            )
          })}
        </Flex>
      )}
      {children}
    </View>
  )
}

const Swiper = memo(Component)
export default Swiper

index.less

.container {
  position: relative;
}

.swiperBox {
  position: relative;
  width: 100vw;
  height: calc(100vw * 638 / 375);

  .swiperItem {
    position: relative;
    width: calc(100% - 5px);
    height: 100%;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 8px;
    margin-left: 5px;
    padding: 15px;

    .button {
      position: absolute;
      top: calc(100vw * 175 / 375);
      
      width: 130px;
      height: 42px;
      
      border-radius: 42px;
      background: #EFD7B1;
      font-weight: 500;
    }
  }

  .swiperItemActive {
    transform: scale(1);
    transition: all 0.8s ease 0s;
  }

  .swiperItemOutLeft {
    transition: all 0.8s ease-out 0.1s;
    transform: translate(20px, 38px) scale(0.88);
  }

  .swiperItemOutRight {
    transition: all 0.8s ease-out 0.1s;
    transform: translate(-20px, 38px) scale(0.88);
  }
}

.dots {
  position: absolute;
  bottom: -15px;
  // gap: 5px; // 有些手機型號無效
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;

  .dot {
    width: 12px;
    height: 2px;
    background-color: #5B5C5C;
    transition: all 0.5s;
    margin-right: 5px;
  }

  .dotActive {
    background-color: #fff;
  }
}

conts.ts

export interface SwiperProps {
  current: number
  modes: xxxx[] // xxx是需要定義的inteface結(jié)構(gòu)
  isDot?: boolean
  onMode?: (plan: CareModelDTO) => void
}

改造Swiper組件,符合業(yè)務(wù)的設(shè)計和動畫效果

改造微信小程序Swiper組件,自定義切換動畫,Taro,前端,javascript,react.js文章來源地址http://www.zghlxwxcb.cn/news/detail-851935.html

到了這里,關(guān)于改造微信小程序Swiper組件,自定義切換動畫的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【微信小程序】swiper和swiper-item組件的基本使用

    【微信小程序】swiper和swiper-item組件的基本使用

    ?作者簡介:CSDN內(nèi)容合伙人、阿里云專家博主、51CTO專家博主?? ??個人主頁:hacker707的csdn博客 ??系列專欄:微信小程序 ??個人格言:不斷的翻越一座又一座的高山,那樣的人生才是我想要的。這一馬平川,一眼見底的活,我不想要,我的人生,我自己書寫,余生很長,請

    2024年02月09日
    瀏覽(97)
  • 【微信小程序】swiper自定義樣式:指示點樣式 wx-swiper-dot

    【微信小程序】swiper自定義樣式:指示點樣式 wx-swiper-dot

    調(diào)試基礎(chǔ)庫:2.26.0 .wx-swiper-dots : 指示點容器樣式 .wx-swiper-dots-horizontal : 水平滑動的指示點容器樣式,其在 .wx-swiper-dots 內(nèi)。 .wx-swiper-dot :指示點樣式 .wx-swiper-dot-active : 當(dāng)前指示點樣式 默認(rèn)指示點顏色 改變指示點顏色 默認(rèn)指示點形狀 改變指示點形狀 默認(rèn)指示點位置貼近

    2024年02月12日
    瀏覽(16)
  • 微信小程序swiper 視頻中間大,兩邊小,輪播滑到中間視頻自動播放組件教程

    微信小程序swiper 視頻中間大,兩邊小,輪播滑到中間視頻自動播放組件教程

    靜態(tài)效果: ?進入下面小程序可以體驗效果 ,點擊底部 看劇 欄目? ?

    2024年02月20日
    瀏覽(117)
  • 【微信小程序】-- 常用視圖容器類組件介紹 -- view、scroll-view和swiper(六)

    【微信小程序】-- 常用視圖容器類組件介紹 -- view、scroll-view和swiper(六)

    ?? 所屬專欄:【微信小程序開發(fā)教程】 ?? 作??者:我是夜闌的狗?? ?? 個人簡介:一個正在努力學(xué)技術(shù)的CV工程師,專注基礎(chǔ)和實戰(zhàn)分享 ,歡迎咨詢! ?? 歡迎大家:這里是CSDN,我總結(jié)知識的地方,喜歡的話請三連,有問題請私信 ?? ?? ?? ??大家好,又見面了,

    2024年01月18日
    瀏覽(98)
  • 微信小程序常用組件的簡單使用 view,scroll-view,swiper,swiper-item,text,rich-text,button,image

    微信小程序常用組件的簡單使用 view,scroll-view,swiper,swiper-item,text,rich-text,button,image

    view組件就類似于html中的div標(biāo)簽 list.wxml list.wxss scroll-view組件就是滾動的視窗,使用scroll-view組件時,要想橫向滾動或者縱向滾動時,需要在scroll-view組件上添加對應(yīng)的屬性 scroll-x 或 scroll-y,然后需要注意的是,縱向滾動需要給scroll-view組件限定高度,橫向滾動則需要給scroll-vi

    2024年02月15日
    瀏覽(786)
  • 微信小程序自定義tabbar切換延遲以及切換閃爍問題

    微信小程序自定義tabbar切換延遲以及切換閃爍問題

    首先,吐槽一番,官方bug,好多年了,一直不解決....那我們就自己解決.. 切換延遲就是點擊tabbar時要點擊兩次icon才能正確選中,比如說首頁要跳轉(zhuǎn)到工單頁面,要點擊兩次工單的圖標(biāo)才被激活; 解決:?在對應(yīng)的要跳轉(zhuǎn)的頁面的show生命周期里面加上以下代碼即可,selected是custom-tab-bar里

    2024年01月21日
    瀏覽(33)
  • 微信小程序在調(diào)用swiper組件時如果出現(xiàn)[渲染層錯誤] Uncaught TypeError: Cannot read property ‘$$‘ of undefined

    微信小程序在調(diào)用swiper組件時如果出現(xiàn)[渲染層錯誤] Uncaught TypeError: Cannot read property ‘$$‘ of undefined

    報錯:TypeError: Cannot read property ‘$$’ of undefined 還需設(shè)置current = 0, 并且current和swiperList不能在一個this.setData中設(shè)置, 要先setData swiperList 然后在setData current

    2024年02月13日
    瀏覽(95)
  • 在微信小程序中如何使用Loading組件顯示載入動畫

    Loading組件是微信小程序中常用的一種UI組件,用于在數(shù)據(jù)加載過程中顯示載入動畫,提高用戶體驗。本文將詳細(xì)介紹如何在微信小程序中使用Loading組件,并提供相應(yīng)的源代碼示例。 創(chuàng)建Loading組件 首先,在小程序的組件文件夾中創(chuàng)建一個名為\\\"loading\\\"的文件夾,并在該文件夾下

    2024年02月03日
    瀏覽(22)
  • 微信小程序+vant組件 側(cè)邊導(dǎo)航欄切換顯示

    設(shè)計頁面時希望效果:左側(cè)側(cè)邊導(dǎo)航欄,右側(cè)內(nèi)容。點擊左側(cè)導(dǎo)航欄的不同塊,右側(cè)顯示不同內(nèi)容。 采用了vant組件中側(cè)邊導(dǎo)航欄van-sidebar,van-sidebar子標(biāo)簽包括多個van-sidebar-item 實現(xiàn)方法: van-sidebar中設(shè)置 bind:change=\\\"onChange\\\": 隨后在js文件中編寫onChange(event),其中event.deta

    2024年02月13日
    瀏覽(20)
  • 【微信小程序】自定義組件(一)

    【微信小程序】自定義組件(一)

    ?? 寫在前面: 觀眾老爺們好呀,這里是前端小劉不怕牛牛頻道,小程序系列文章又更新了呀。 今天牛牛帶來的是微信小程序的自定義組件入門知識,趕緊拿起小本本做筆記呀! 1.1 介紹 自定義組件,就是開發(fā)者將頁面的某個功能模塊抽象化并提取出來的代碼塊,支持復(fù)用,

    2023年04月08日
    瀏覽(145)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包