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

html-css07

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类似的效果

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

方法1:直接在body里面加上属性scroll

代码如:

<

body

scroll=“no”

>

方法2:使用样式表overflow

代码如:

html{overflow:hidden;}-----我采用了这个,滚动条就消失了,最开始一直误以为是页面里面的div高度不当导致出现的滚动条。

在xhtml1-transitional.dtd标准下,并不是以body为容器,而是html标签,所以要把样式表加到html标签上才行,加到body上是不管用的。

<marquee direction=up behavior=scroll loop=3 scrollamount=1 scrolldelay=10 align=top bgcolor=#ffffff height=300 width=30% hspace=20 vspace=10 onmouseover=this.stop() onmouseout=this.start()>此处输入滚动内容 </marquee>

◎ direction表示滚动的方向,值可以是left,right,up,down,默认为left

◎ behavior表示滚动的方式,值可以是scroll(连续滚动)slide(滑动一次)alternate(往返滚动)

◎ loop表示循环的次数,值是正整数,默认为无限循环

◎ scrollamount表示运动速度,值是正整数,默认为6

◎ scrolldelay表示停顿时间,值是正整数,默认为0,单位似乎是毫秒

◎ align表示元素的垂直对齐方式,值可以是top,middle,bottom,默认为middle

◎ bgcolor表示运动区域的背景色,值是16进制的RGB颜色,默认为白色

◎ height、width表示运动区域的高度和宽度,值是正整数(单位是像素)或百分数,默认width=100% height为标签内元素的高度

◎ hspace、vspace表示元素到区域边界的水平距离和垂直距离,值是正整数,单位是像素。

◎ onmouseover=this.stop() onmouseout=this.start()表示当鼠标以上区域的时候滚动停止,当鼠标移开的时候又继续滚动。