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

JavaScript014

h5嵌入app 以及页面全屏滚动动画,第1张

<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.clientHeighte&&(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)

---  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)

--- 引用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.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)

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

--- 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.js 与 animate.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: centerfont: 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类似的效果

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

最近项目中接入 video.js 框架,在安卓机上 全屏 时, 有声音无画面

通过调试,发现在全屏后,video标签 width &height 均为0,

经过查看video.js官网文档,检查播放器实例配置,无误,Google各种方案无果。

果断放弃video自带的全屏方案。

通过修改video标签旋转,按宽高比放大视频至设备屏幕宽高

此时可以实现全屏效果。

但是问题又出现了,手机的20px的 状态条 仍旧在 =_=#

可以结合cordova插件 cordova-plugin-statusbar 插件实现。

【插件地址 传送门】

至此,曲线救国,问题修复。

//需要连接 连接的三个文件 <link rel="stylesheet" href="css/jquery.fullPage.css"> //css文件 <script src="js/jquery-1.8.3.min.js"></script>   //jQuery 1.8.3的版本 <script src="js/jquery.fullPage.min.js"></script>   //fullPage插件的压缩版本 <style> .section { text-align: center font: 50px "Microsoft Yahei" color: #fff}  //可以改动 设置的是网页中的文字 <无关紧要> </style> <script> $(function(){  $('#dowebok').fullpage({   //fullpage  比较重要 设置的是插件的基本设置 后面的  sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', '#f90']   //sectionsColor 当没有背景图片的时候这个就是设置背景颜色的否则就是空白 数组的形式 中间以逗号隔开 颜色不管是十六进制还是英文单词都需要用单引号包着  }) }) </script> <div id="dowebok">          //绑定的大盒子 设置滚动的盒子  <div class="section">  <h3>第一屏</h3>  <p>fullPage.js — 基本演示</p>  </div>  <div class="section">        //滚动的第二屏幕 如果在里面添加div和slide的样式就可以增加横向 点击  <div class="slide"><h3>第二屏的第一屏</h3></div>  <div class="slide"><h3>第二屏的第二屏</h3></div>  <div class="slide"><h3>第二屏的第三屏</h3></div>  </div>  <div class="section">  <h3>第三屏</h3>  </div>  <div class="section">  <h3>第四屏</h3>  <p>这是最后一屏</p>  </div> </div> 0.02  插入背景图片演示  的HTML 布局 以及js 代码 <需要链接的文件都是一样的> <style>          //需要注意的是这里 没有设置颜色 而是在css中设置的背景图片0 .section1 { background: url(images/1.jpg) 50%} .section2 { background: url(images/2.jpg) 50%} .section3 { background: url(images/3.jpg) 50%} .section4 { background: url(images/4.jpg) 50%} </style> <script> $(function(){  $('#dowebok').fullpage()     //找到大盒子 设置fullpage全屏滚动 }) </script> <div id="dowebok">  <div class="section section1"></div>  <div class="section section2"></div>  <div class="section section3"></div>  <div class="section section4"></div> </div> 0.03 循环演示 html 布局以及js代码 <需要链接的文件都是一样的> <script> $(function(){  $('#dowebok').fullpage({   sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', '#f90'], //和上面一样 sectionsColor 是设置每一屏的颜色 必须用逗号隔开 单引号包着   continuousVertical: false,         //设置是否滑到底层再往下滚动是第一张图 设置true是执行此操作 设置false是不执行 默认不执行 不执行就不设置  }) }) </script> <div id="dowebok">  <div class="section">   <h3>第一屏</h3>   <p>fullPage.js — 循环演示</p>  </div>  <div class="section">   <h3>第二屏</h3>  </div>  <div class="section">   <h3>第三屏</h3>  </div>  <div class="section">   <h3>第四屏</h3>   <p>这是最后一屏了,继续往下滚返回第一屏</p>  </div> </div> 0.04  回调函数演示 <title>fullPage.js — 回调函数演示</title> <link rel="stylesheet" href="css/jquery.fullPage.css"> <style> .section { text-align: center font: 50px "Microsoft Yahei" color: #fff} .section2 p { position: relative left: -120%} .section3 p { position: relative bottom: -120%} .section4 p { display: none} </style> <script src="js/jquery.min.js"></script> <script src="js/jquery-ui.js"></script> <script src="js/jquery.fullPage.js"></script> <script> $(function(){  $('#dowebok').fullpage({   sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', '#f90'],   //设置背景颜色   afterLoad: function(anchorLink, index){   //滚动到某一屏后的回调函数,接收 anchorLink 和 index 两个参数,anchorLink 是锚链接的名称,index 是序号,从1开始计算    if(index == 2){     $('.section2').find('p').delay(500).animate({        //find('p') 搜索所有段落中的后代 p 元素        //delay(500)其中参数为延时值,它的单位是毫秒        //animate() 方法执行 CSS 属性集的自定义动画      left: '0'     }, 1500, 'easeOutExpo') //jQuery Easing 动画效果扩展    }    if(index == 3){     $('.section3').find('p').delay(500).animate({      bottom: '0'     }, 1500, 'easeOutExpo')    }    if(index == 4){     $('.section4').find('p').fadeIn(2000)     //fadeIn() 方法逐渐改变被选元素的不透明度,从隐藏到可见(褪色效果)    }   },   onLeave: function(index, direction){   //滚动前的回调函数,接收 index、nextIndex 和 direction 3个参数:index 是离开的“页面”的序号,从1开始计算;   //nextIndex 是滚动到的“页面”的序号,从1开始计算;   //direction 判断往上滚动还是往下滚动,值是 up 或 down。    if(index == '2'){     $('.section2').find('p').delay(500).animate({      left: '-120%'     }, 1500, 'easeOutExpo')    }    if(index == '3'){     $('.section3').find('p').delay(500).animate({      bottom: '-120%'     }, 1500, 'easeOutExpo')    }    if(index == '4'){     $('.section4').find('p').fadeOut(2000)     //fadeOut() 方法逐渐改变被选元素的不透明度,从可见到隐藏(褪色效果)    }   },   continuousVertical: false,   // 是否循环滚动,与 loopTop 及 loopBottom 不兼容  }) }) </script> <div id="dowebok">  <div class="section section1">   <h3>第一屏</h3>   <p>fullPage.js — 回调函数演示</p>  </div>  <div class="section section2">   <h3>第二屏</h3>   <p>滚动到第二屏后的回调函数执行的效果</p>  </div>  <div class="section section3">   <h3>第三屏</h3>   <p>滚动到第三屏后的回调函数执行的效果</p>  </div>  <div class="section section4">   <h3>第四屏</h3>   <p>滚动到第四屏后的回调函数执行的效果</p>  </div> </div>

参考资料

脚本之家.脚本之家[引用时间2018-1-24]