移动端 H5 场景应用【破茧成蝶】案例鉴赏

2023-12-27 02:30

本文主要是介绍移动端 H5 场景应用【破茧成蝶】案例鉴赏,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

移动端 H5 场景应用【破茧成蝶】案例鉴赏

移动端【破茧成蝶】场景请用微信扫描二维码访问(温馨提示:H5案例有声音,请打开声音体验):

在这里插入图片描述
案例:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<meta name="viewport" content="width=640, user-scalable=no,target-densityDpi=device-dpi">
<style>
*{ margin:0; padding:0;}
html{ overflow:hidden;}
li{ list-style:none;}
#main{ width:640px; height:auto; position:relative; overflow:hidden;}
#c1{ width:100%; height:100%; position:absolute; left:0; top:0; z-index:10;}
#list{}
#list > li{ width:100%; height:100%; background-repeat:no-repeat; position:absolute; left:0; top:0; background-size:cover; z-index:5; display:none;}
#list > li.zIndex{ z-index:6;}
#list > li:nth-of-type(1){ background-image:url(img/b.png); display:block;}
#list > li:nth-of-type(2){ background-image:url(img/c.png);}
#list > li:nth-of-type(3){ background-image:url(img/d.png);}
#list > li:nth-of-type(4){ background-image:url(img/e.png);}
#list > li:nth-of-type(5){ background-image:url(img/ad1.png);}
#list > li:nth-of-type(6){ background-image:url(img/ad2.png);}
#list > li:nth-of-type(7){ background-image:url(img/ad3.png);}
#list > li:nth-of-type(8){ background-image:url(img/ad4.png);}
</style>
<script src="jquery-2.1.3.min.js"></script>
<script>
$(document).on('touchmove',function(ev){ev.preventDefault();
});
$(function(){var $main = $('#main');var $list = $('#list');var $li = $list.find('>li');var viewHeight = $(window).height();$main.css('height',viewHeight);slideCanvas();slideImg(); function slideCanvas(){var $c = $('#c1');var gc = $c.get(0).getContext('2d');var img = new Image();var bBtn = true;$c.attr('height',viewHeight);img.src = 'img/a.png';      img.onload = function(){gc.drawImage(img,(640 - nowViewWidth())/2,0,nowViewWidth(),viewHeight);gc.strokeStyle = 'blue';gc.lineWidth = 60;gc.lineCap = 'round';gc.globalCompositeOperation = 'destination-out';$c.on('touchstart',function(ev){    var touch = ev.originalEvent.changedTouches[0];var x = touch.pageX - $(this).offset().left;var y = touch.pageY - $(this).offset().top;/*gc.arc(x,y,100,0,360*Math.PI/180);gc.fill();*/if(bBtn){bBtn = false;gc.moveTo(x,y);gc.lineTo(x+1,y+1);}else{gc.lineTo(x,y);}gc.stroke();$c.on('touchmove.move',function(ev){    var touch = ev.originalEvent.changedTouches[0];var x = touch.pageX - $(this).offset().left;var y = touch.pageY - $(this).offset().top;gc.lineTo(x,y);gc.stroke();                    });$c.on('touchend.move',function(ev){var imgData = gc.getImageData(0,0,640,viewHeight);var allPx = imgData.width * imgData.height;var num = 0;for(var i=0;i<allPx;i++){if( imgData.data[4*i+3] == 0 ){num++;}}if( num > allPx/2 ){$c.animate({opacity:0},1000,function(){$(this).remove();});}$c.off('.move');});}); };}   function slideImg(){var startY = 0;var step = 1/4;var nowIndex = 0;var nextorprevIndex = 0;var bBtn = true;$li.css('backgroundPosition', (640 - nowViewWidth())/2 +'px 0');$li.on('touchstart',function(ev){if(bBtn){bBtn = false;var touch = ev.originalEvent.changedTouches[0];startY = touch.pageY;nowIndex = $(this).index();$li.on('touchmove.move',function(ev){var touch = ev.originalEvent.changedTouches[0];$(this).siblings().hide();if( touch.pageY < startY ){   //↑nextorprevIndex = nowIndex == $li.length-1 ? 0 : nowIndex + 1;$li.eq(nextorprevIndex).css('transform','translate(0,'+( viewHeight + touch.pageY - startY )+'px)');                    }else{   //↓nextorprevIndex = nowIndex == 0 ? $li.length-1 : nowIndex - 1;$li.eq(nextorprevIndex).css('transform','translate(0,'+( -viewHeight + touch.pageY - startY )+'px)');                   }$li.eq(nextorprevIndex).show().addClass('zIndex');//Math.abs((touch.pageY - startY))/viewHeight -> 最大值 -viewHeight~viewHeight$(this).css('transform','translate(0,'+ (touch.pageY - startY)*step +'px) scale('+(1 - Math.abs((touch.pageY - startY))*step/viewHeight )+')');});     $li.on('touchend.move',function(ev){var touch = ev.originalEvent.changedTouches[0];if( touch.pageY < startY ){   //↑$li.eq(nowIndex).css('transform','translate(0,'+(-viewHeight * step)+'px) scale('+(1 - step)+')');}else{  //↓$li.eq(nowIndex).css('transform','translate(0,'+(viewHeight * step)+'px) scale('+(1 - step)+')');}$li.eq(nowIndex).css('transition','.3s');$li.eq(nextorprevIndex).css('transform','translate(0,0)');$li.eq(nextorprevIndex).css('transition','.3s');$li.off('.move');});}});$li.on('transitionEnd webkitTransitionEnd',function(){resetFn();});function resetFn(){$li.css('transform','');$li.css('transition','');$li.eq(nextorprevIndex).removeClass('zIndex').siblings().hide();bBtn = true;}}function nowViewWidth(){var w = 640 * viewHeight / 960;w = w > 640 ? w : 640;return w;}   
});
</script>
</head>
<body>
<div id="main"><canvas id="c1" width="640" height="960"></canvas><ul id="list"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul>
</div>
</body>
</html>

一、什么是微信场景应用

二、场景运行环境

  1. 微信内嵌的浏览器
  2. Chrome自带移动端Emulation(模拟器)

三、场景一功能

  1. 加载,刮开,划屏,动画,音乐等

四、jQuery

  1. 版本2.1.3

五、手机分辨率

  1. 屏幕
  2. 设备

六、主流屏幕分辨率

  1. 640 * 960
  2. 640 * 1136

七、viewport

  1. 默认视口
  2. width=device-width , user-scalable=no
  3. target-densityDpi=device-dpi
  4. 固定值640即可

八、设置高度

  1. 通过JS动态设置
  2. background-size : cover

九、刮开效果

  1. canvas
  2. globalCompositeOperation
    a. source-over
    b. destination-over
    c. destination-out

十、移动端事件

  1. touchstart
  2. touchmove
  3. touchend
  4. 原生event
    a. originalEvent
    b. changedTouches
  5. 阻止默认touchmove
    a. preventDefault

十一、划屏切换

  1. css3
  2. 运动实现
  3. transform
    a. translate
    b. scale
    c. transition
    d. transitionEnd事件

十二、提示箭头

  1. css3
    a. animation
    b. 名字
    c. 时间
    d. 执行次数
    e. infinite
  2. @keyframes
    a. 帧

十三 、入场动画

  1. 文字样式
  2. css3+js
    a. transform
    b. transition
  3. 图标
    a. 可以用图片
    b. 也可以用字体库,Font Awesome

十四、音乐

  1. audio
    a. play()
    b. pause()

十五、加载

  1. css3
  2. 控制scale
  3. animation-delay
  4. js
  5. new Image

十六、查看场景二效果

  1. 声音,音乐,加载,3D魔方,3D划屏,粒子操作

十七、适配

  1. 第二种模式方案

十八、音乐

  1. audio
  2. play()
  3. pause()

十九、3D魔方

  1. perspective
  2. preserve-3d
  3. transform-origin

二十、3D划屏

  1. translateZ

二十一、粒子操作

  1. canvas像素级操作
  2. canvas运动模式

二十二、加载

  1. linear-gradient

妙味课堂–案例详情

这篇关于移动端 H5 场景应用【破茧成蝶】案例鉴赏的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/541603

相关文章

Java逻辑运算符之&&、|| 与&、 |的区别及应用

《Java逻辑运算符之&&、||与&、|的区别及应用》:本文主要介绍Java逻辑运算符之&&、||与&、|的区别及应用的相关资料,分别是&&、||与&、|,并探讨了它们在不同应用场景中... 目录前言一、基本概念与运算符介绍二、短路与与非短路与:&& 与 & 的区别1. &&:短路与(AND)2. &:非短

Android WebView无法加载H5页面的常见问题和解决方法

《AndroidWebView无法加载H5页面的常见问题和解决方法》AndroidWebView是一种视图组件,使得Android应用能够显示网页内容,它基于Chromium,具备现代浏览器的许多功... 目录1. WebView 简介2. 常见问题3. 网络权限设置4. 启用 JavaScript5. D

Spring AI集成DeepSeek三步搞定Java智能应用的详细过程

《SpringAI集成DeepSeek三步搞定Java智能应用的详细过程》本文介绍了如何使用SpringAI集成DeepSeek,一个国内顶尖的多模态大模型,SpringAI提供了一套统一的接口,简... 目录DeepSeek 介绍Spring AI 是什么?Spring AI 的主要功能包括1、环境准备2

Spring AI与DeepSeek实战一之快速打造智能对话应用

《SpringAI与DeepSeek实战一之快速打造智能对话应用》本文详细介绍了如何通过SpringAI框架集成DeepSeek大模型,实现普通对话和流式对话功能,步骤包括申请API-KEY、项目搭... 目录一、概述二、申请DeepSeek的API-KEY三、项目搭建3.1. 开发环境要求3.2. mav

MobaXterm远程登录工具功能与应用小结

《MobaXterm远程登录工具功能与应用小结》MobaXterm是一款功能强大的远程终端软件,主要支持SSH登录,拥有多种远程协议,实现跨平台访问,它包括多会话管理、本地命令行执行、图形化界面集成和... 目录1. 远程终端软件概述1.1 远程终端软件的定义与用途1.2 远程终端软件的关键特性2. 支持的

Python爬虫selenium验证之中文识别点选+图片验证码案例(最新推荐)

《Python爬虫selenium验证之中文识别点选+图片验证码案例(最新推荐)》本文介绍了如何使用Python和Selenium结合ddddocr库实现图片验证码的识别和点击功能,感兴趣的朋友一起看... 目录1.获取图片2.目标识别3.背景坐标识别3.1 ddddocr3.2 打码平台4.坐标点击5.图

Python重命名文件并移动到对应文件夹

《Python重命名文件并移动到对应文件夹》在日常的文件管理和处理过程中,我们可能会遇到需要将文件整理到不同文件夹中的需求,下面我们就来看看如何使用Python实现重命名文件并移动到对应文件夹吧... 目录检查并删除空文件夹1. 基本需求2. 实现代码解析3. 代码解释4. 代码执行结果5. 总结方法补充在

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

使用Navicat工具比对两个数据库所有表结构的差异案例详解

《使用Navicat工具比对两个数据库所有表结构的差异案例详解》:本文主要介绍如何使用Navicat工具对比两个数据库test_old和test_new,并生成相应的DDLSQL语句,以便将te... 目录概要案例一、如图两个数据库test_old和test_new进行比较:二、开始比较总结概要公司存在多

5分钟获取deepseek api并搭建简易问答应用

《5分钟获取deepseekapi并搭建简易问答应用》本文主要介绍了5分钟获取deepseekapi并搭建简易问答应用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需... 目录1、获取api2、获取base_url和chat_model3、配置模型参数方法一:终端中临时将加