h5嵌入app 以及页面全屏滚动动画

1、移动端适配rem:

<script type="text/javascript">

!function(e,t){var i=e.documentElement,n="orientationchange"in window?"orientationchange":"resize",a=navigator.userAgent.match(/iphone|ipad|ipod/i),d=function(){var e=i.clientWidth,t=i.clientHeight;e&&(750<=e&&(e=750),i.style.fontSize=e/750*100+"px",i.dataset.percent=e/750*100,i.dataset.width=e,i.dataset.height=t)};d(),a&&e.documentElement.classList.add("iosx"+t.devicePixelRatio),e.addEventListener&&t.addEventListener(n,d,!1)}(document,window)

</script>

(设计稿尺寸为750)




2、h5调用app方法

---  getToken()为定义的方法名称:

安卓:window.native.方法名()

eg:

  TOKEN = window.native ? window.native.getToken() : '';

  appVersion = window.native ? window.native.getAppVersionName() : '';

  uuid = window.native ? window.native.getUUId() : '';

  phoneModel = window.native ? window.native.getPhoneModel() : '';

  clientId = window.native ? window.native.getClientId() : '';


ios:window.webkit.messageHandlers.方法名.postMessage(null);

eg: 如果没有参数 要写上null

    window.webkit.messageHandlers.getToken.postMessage(null);

    window.webkit.messageHandlers.getClientId.postMessage(null);

    window.webkit.messageHandlers.getPhoneModel.postMessage(null);

    window.webkit.messageHandlers.getUUId.postMessage(null);

    window.webkit.messageHandlers.getAppVersionName.postMessage(null);




3、h5在APP上调试:

--- 引用vconsole.js

<script src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"></script>

  <script type="text/javascript">

     var vConsole = new VConsole();

  </script>

(app上可查看log network 相关信息展示)



4、遇到的一些问题:

4.1 --- alert localStorage相关属性失效

查找原因:console.log(window) 打印查看APP里没有相关属性 

解决办法:

寻找app相关人员 加上相关属性。

或者如果有时间原因可以尝试(不一定都适用):

alert换成原生自己写的弹框展示 

localStorage换成全局变量

4.2 ---  使用fullpage.js插件 app里页面空白 浏览器查看页面正常

原因:fullpage.js全屏插件设置html body 高度100%  而APP里面设置高度为依据h5页面高度 导致h5嵌套进去 高度为0 页面自然空白 

解决办法: 

1:app修改设置 参考回答:https://stackoverflow.com/questions/32729416/html-height-100-ignored-by-webview 


2:h5 初始化插件之后 再设置html body高度为100%, body等元素背景图片 

eg:

$('#fullPage').fullpage({}); 

$('html').css('height',window.innerHeight)

$('html').css('width',window.innerWidth)

$('html').css({'background':'url(https://zhuoyou-shop.oss-cn-hangzhou.aliyuncs.com/static/lottery/img/bk.jpg) no-repeat center','background-size':'cover'})

$('body').css('height',window.innerHeight)

$('body').css('width',window.innerWidth)




5、页面进入或滚动 展示相关动画:

--- 页面在向下滚动的时候,有些元素会产生细小的动画效果。虽然动画比较小,但却能吸引浏览者的注意,使页面更吸人眼球。

--- WOW.js 依赖animate.css,所以它支持 animate.css 多种的动画效果,能满足各种需求。

--- IE6、IE7 等老旧浏览器不支持 CSS3 动画,所以没有效果;而 wow.js 也使用了 querySelectorAll 方法,IE 低版本会报错。为了达到更好的兼容,最好加一个浏览器及版本判断。

使用方法:

1、引入文件

<link rel="stylesheet" href="css/animate.min.css">

2、HTML

<div class="wow slideInLeft"></div>

<div class="wow slideInRight"></div>

可以加入 data-wow-duration(动画持续时间)和 data-wow-delay(动画延迟时间)属性,如:

<div class="wow slideInLeft" data-wow-duration="2s" data-wow-delay="5s"></div>

<div class="wow slideInRight" data-wow-offset="10"  data-wow-iteration="10"></div>

3、JavaScript

new WOW().init();

如果需要自定义配置,可如下使用:

var wow = new WOW({

    boxClass: 'wow', //‘wow’需要执行动画的元素的 class

    animateClass: 'animated', //‘animated’animation.css 动画的 class

    offset: 0, //0距离可视区域多少开始执行动画

    mobile: true, //true是否在移动设备上执行动画

    live: true //true异步加载的内容是否有效

});

wow.init();




一个demo尝试:

是要引入animate.css和wow.js的

html

<ul class="list2">

<li class="wow fadeInLeft animated"></li>

<li class="wow fadeInRight animated" data-wow-delay="0.3s"></li>

<li class="wow fadeInLeft animated" data-wow-delay="0.6s"></li>

<li class="wow fadeInRight animated" data-wow-delay="0.9s"></li>

</ul>

<ul class="ft-service">

<li class="wow fadeInUpBig animated"></li>

<li class="wow fadeInUpBig animated" data-wow-delay="0.3s"></li>

<li class="wow fadeInUpBig animated" data-wow-delay="0.6s"></li>

<li class="wow fadeInUpBig animated" data-wow-delay="0.9s"></li>

<li class="wow fadeInUpBig animated" data-wow-delay="1.2s"></li>

</ul>

css

ul{

width: 1200px;

overflow: hidden;

}

.list2{

width: 760px;

display: flex;

justify-content: space-between;

flex-wrap: wrap;

}

.list2 .wow{

display: inline-block;

    width: 50%;

    height: 560px;

background-image: url(https://cdn.dowebok.com/131/images/i2/list2-5.jpg);

}

.ft-service .wow {

    display: inline-block;

    width: 236px;

    height: 125px;

    background-image: url(https://cdn.dowebok.com/131/images/i2/ft-service.png);

    background-repeat: no-repeat;

}

js

<script type="text/javascript">

var wow = new WOW({

    boxClass: 'wow',

    animateClass: 'animated', 

    offset: 0,

    mobile: true,

    live: true

});

wow.init();

</script>

这样就有了一个可以自己发挥的动画效果了。

就是一个比较方便的进入 或者 滚动 的时候的页面的加载动画了,可以随意加入自己想要的动画。

animate.css也可以与别的插件结合使用 比如 fullpage.js都是可以有这种页面进入 滚动时候加入动画的效果。




fullpage.jsanimate.css实现的动画效果:

demo

也是要引入相关文件 fullpage.js  fullpage.css  animate.css

HTML

<div id="fullPage">

  <div class="section">

    <h3 id="p1" class="display">第一屏</h3>

  </div>

  <div class="section">

  <h3 id="p2" class="display" onclick="getNext()">向上滑动</h3>

  </div>

  <div class="section">

    <h3 id="p3" class="display">第三屏</h3>

  </div>

  <div class="section">

    <h3 id="p4" class="display">第四屏</h3>

    <p id="p5" class="display">这是最后一屏</p>

    <p id="p6" class="display" onclick="getTop()">返回首屏</p>

  </div>

</div>

css

.section { text-align: center; font: 50px "Microsoft Yahei"; color: #fff;}

.section p{font: 30px "Microsoft Yahei";}

.display{display: none;}

.display1{display: block;}

JS:

<script>

$(function(){

$('#fullPage').fullpage({

sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', '#f90'],

//滚动到某一屏后

afterLoad: function(anchorLink, index){

if(index == 1){ 

        $('#p1').addClass('animate__animated animate__bounceInLeft display1');

}

if(index == 2){ 

        $('#p2').addClass('animate__animated animate__bounceInLeft display1');

}

if(index == 3){ 

        $('#p3').addClass('animate__animated animate__bounceInLeft display1');

}

if(index == 4){ 

        $('#p4').addClass('animate__animated animate__bounceInLeft display1');

        $('#p5').addClass('animate__animated animate__bounceInLeft animate__delay-1s display1');

        $('#p6').addClass('animate__animated animate__bounceInLeft animate__delay-2s display1');

}

},

onLeave: function(index, direction){

      if(index == '1'){ 

        $('#p1').removeClass('animate__animated animate__bounceInLeft display1');

}

if(index == '2'){ 

        $('#p2').removeClass('animate__animated animate__bounceInLeft display1');

}

if(index == '3'){ 

        $('#p3').removeClass('animate__animated animate__bounceInLeft display1');

}

if(index == '4'){ 

        $('#p4').removeClass('animate__animated animate__bounceInLeft display1');

        $('#p5').removeClass('animate__animated animate__bounceInLeft animate__delay-1s display1');

        $('#p6').removeClass('animate__animated animate__bounceInLeft animate__delay-2s display1');

}

}

});

});

//跳转到某一屏

function getNext(){

$.fn.fullpage.moveTo(3);

}

//没有动画的跳转到首屏

function getTop(){

$.fn.fullpage.silentMoveTo(1);

}

</script>

这样的话 也有和wow.js类似的效果

都是页面进入 和 滚动时候 给元素加入动画效果。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269

推荐阅读更多精彩内容