惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
小众软件
小众软件
Recent Announcements
Recent Announcements
博客园 - 三生石上(FineUI控件)
Security Archives - TechRepublic
Security Archives - TechRepublic
W
WeLiveSecurity
Cloudbric
Cloudbric
博客园 - 司徒正美
美团技术团队
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
PCI Perspectives
PCI Perspectives
宝玉的分享
宝玉的分享
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
Last Week in AI
Last Week in AI
S
Schneier on Security
N
News | PayPal Newsroom
B
Blog RSS Feed
L
LINUX DO - 最新话题
T
Troy Hunt's Blog
S
Secure Thoughts
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
L
Lohrmann on Cybersecurity
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tenable Blog
S
Securelist
L
LangChain Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
InfoQ
H
Heimdal Security Blog
Cisco Talos Blog
Cisco Talos Blog
F
Full Disclosure
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
K
Kaspersky official blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
C
Cisco Blogs

博客园 - 进军的蜗牛

浏览器音频入门:录音生成 PCM、单声道/立体声、采样率、转 MP3 Web 语音场景下多路麦克风采集与音量异常:成因与两种工程取舍 从一次权限错误,彻底搞懂Mac权限管理那些事 js实现svga编辑器 Chrome浏览器普通模式访问页面报错 ERR_CONNECTION_REFUSED 问题排查 Web语音聊天室中录音无声问题分析与解决方案 蓝湖SVG上传Iconfont阿里图标库部分元素缺失问题分析与解决方案 前端测试新体验:Cypress让UI测试变得如此简单 iOS H5页面高度闪烁问题与100vh兼容性详解 为什么录音生成的音频文件有时长但没声音?—— 一次音频采集问题的排查与解决 前端实现采集图片某个区域的颜色色值 浏览器多Tab间通信方法全面总结:从WebView需求出发的技术方案 pcm文件转为mp3并播放 github https方式 push无法提交代码的处理方法 前端如何计算js代码执行时长 混合开发H5页面的数字字体在IOS 安卓上显示不一样 node基于自签名证书搭建https服务 ios系统上h5页面点击播放audio标签声音有延迟问题处理 基于svelte webpack开发umd格式的npm包 CSS运动路径offset-path之path的语法解析
基于swiper和animate.css的全屏H5动效和花瓣飘落效果
进军的蜗牛 · 2025-01-24 · via 博客园 - 进军的蜗牛

Animate官网 animate.css

Swiper官网 swiper

Dom 主体结构:

<div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide swiperItem1"></div>
            <div class="swiper-slide swiperItem2"></div>
            <div class="swiper-slide swiperItem3"></div>
        </div>
    </div>

凡是需要使用animate.css 动画的元素 都添加 animate__animated类, 和data-class属性, data-class 的属性就是动画类

 <div class="wordCtn animate__animated" data-class="animate__fadeInUp">一见倾心</div>

Js关键代码:

async function initSwiper () {
        let changeTime = 500; //  翻页时间
        let swiper = new Swiper('.swiper-container',{
            direction : 'vertical',
            followFinger : false,
            speed: changeTime,
            mousewheel: true,
            on:{
                init:function(swiper) {
                    slide = this.slides.eq(0);
                    let doms = $(slide).find('.animate__animated');
                    Array.prototype.forEach.call(doms, function(dom) {
                        let subClass = dom.dataset.class;
                        $(dom).addClass(subClass);
                    });
                },
                transitionStart: function() {
                    setTimeout(() => { // 是为了 翻页的时候 之前的元素 不要隐藏,翻过去之后再隐藏
                        for(i = 0; i < this.slides.length; i++){
                            slide = this.slides.eq(i);
                            let doms = $(slide).find('.animate__animated');
                            Array.prototype.forEach.call(doms, function(dom) {
                                let subClass = dom.dataset.class;
                                $(dom).removeClass(subClass);
                            });
                        }
                    }, changeTime);
                },
                transitionEnd: function() {
                    slide = this.slides.eq(this.activeIndex);
                    // 滚动到最后一页隐藏箭头
                    if (this.slides.length - 1 == this.activeIndex) {
                       $('.arrowDownImg').hide();
                    } else {
                        $('.arrowDownImg').show();
                    }
                    let doms = $(slide).find('.animate__animated');
                    Array.prototype.forEach.call(doms, function(dom) {
                        let subClass = dom.dataset.class;
                        $(dom).addClass(subClass);
                    });
                },
            }
        });
    }

Js代码的思路:

  1. 在 init 的时候给当前页面需要播放动画的元素添加动画类,从data-class 获取
  2. transitionStart 是滑动开的时候触发,这时候不能立马移除 在第一步添加的data-class 属性,需要等翻页动画结束再移除
  3. transitionEnd 是翻页效果结果,到了下一页,这时候开始播放动画,就是把当前页面的data-class 添加到元素的class上

效果如下: