移动端 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

相关文章

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

水位雨量在线监测系统概述及应用介绍

在当今社会,随着科技的飞速发展,各种智能监测系统已成为保障公共安全、促进资源管理和环境保护的重要工具。其中,水位雨量在线监测系统作为自然灾害预警、水资源管理及水利工程运行的关键技术,其重要性不言而喻。 一、水位雨量在线监测系统的基本原理 水位雨量在线监测系统主要由数据采集单元、数据传输网络、数据处理中心及用户终端四大部分构成,形成了一个完整的闭环系统。 数据采集单元:这是系统的“眼睛”,

Hadoop企业开发案例调优场景

需求 (1)需求:从1G数据中,统计每个单词出现次数。服务器3台,每台配置4G内存,4核CPU,4线程。 (2)需求分析: 1G / 128m = 8个MapTask;1个ReduceTask;1个mrAppMaster 平均每个节点运行10个 / 3台 ≈ 3个任务(4    3    3) HDFS参数调优 (1)修改:hadoop-env.sh export HDFS_NAMENOD

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

深入探索协同过滤:从原理到推荐模块案例

文章目录 前言一、协同过滤1. 基于用户的协同过滤(UserCF)2. 基于物品的协同过滤(ItemCF)3. 相似度计算方法 二、相似度计算方法1. 欧氏距离2. 皮尔逊相关系数3. 杰卡德相似系数4. 余弦相似度 三、推荐模块案例1.基于文章的协同过滤推荐功能2.基于用户的协同过滤推荐功能 前言     在信息过载的时代,推荐系统成为连接用户与内容的桥梁。本文聚焦于

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

hdu1394(线段树点更新的应用)

题意:求一个序列经过一定的操作得到的序列的最小逆序数 这题会用到逆序数的一个性质,在0到n-1这些数字组成的乱序排列,将第一个数字A移到最后一位,得到的逆序数为res-a+(n-a-1) 知道上面的知识点后,可以用暴力来解 代码如下: #include<iostream>#include<algorithm>#include<cstring>#include<stack>#in

zoj3820(树的直径的应用)

题意:在一颗树上找两个点,使得所有点到选择与其更近的一个点的距离的最大值最小。 思路:如果是选择一个点的话,那么点就是直径的中点。现在考虑两个点的情况,先求树的直径,再把直径最中间的边去掉,再求剩下的两个子树中直径的中点。 代码如下: #include <stdio.h>#include <string.h>#include <algorithm>#include <map>#

【区块链 + 人才服务】可信教育区块链治理系统 | FISCO BCOS应用案例

伴随着区块链技术的不断完善,其在教育信息化中的应用也在持续发展。利用区块链数据共识、不可篡改的特性, 将与教育相关的数据要素在区块链上进行存证确权,在确保数据可信的前提下,促进教育的公平、透明、开放,为教育教学质量提升赋能,实现教育数据的安全共享、高等教育体系的智慧治理。 可信教育区块链治理系统的顶层治理架构由教育部、高校、企业、学生等多方角色共同参与建设、维护,支撑教育资源共享、教学质量评估、

客户案例:安全海外中继助力知名家电企业化解海外通邮困境

1、客户背景 广东格兰仕集团有限公司(以下简称“格兰仕”),成立于1978年,是中国家电行业的领军企业之一。作为全球最大的微波炉生产基地,格兰仕拥有多项国际领先的家电制造技术,连续多年位列中国家电出口前列。格兰仕不仅注重业务的全球拓展,更重视业务流程的高效与顺畅,以确保在国际舞台上的竞争力。 2、需求痛点 随着格兰仕全球化战略的深入实施,其海外业务快速增长,电子邮件成为了关键的沟通工具。