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>
(設(shè)計(jì)稿尺寸為750)
2乳幸、h5調(diào)用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: 如果沒有參數(shù) 要寫上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上調(diào)試:
--- 引用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 相關(guān)信息展示)
4钧椰、遇到的一些問題:
4.1 --- alert?localStorage相關(guān)屬性失效
查找原因:console.log(window) 打印查看APP里沒有相關(guān)屬性?
解決辦法:
尋找app相關(guān)人員 加上相關(guān)屬性。
或者如果有時間原因可以嘗試(不一定都適用):
alert換成原生自己寫的彈框展示?
localStorage換成全局變量
4.2 ---? 使用fullpage.js插件 app里頁面空白 瀏覽器查看頁面正常
原因:fullpage.js全屏插件設(shè)置html body 高度100%? 而APP里面設(shè)置高度為依據(jù)h5頁面高度 導(dǎo)致h5嵌套進(jìn)去 高度為0 頁面自然空白?
解決辦法:?
1:app修改設(shè)置 參考回答:https://stackoverflow.com/questions/32729416/html-height-100-ignored-by-webview?
2:h5 初始化插件之后 再設(shè)置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嫡霞、頁面進(jìn)入或滾動 展示相關(guān)動畫:
--- 頁面在向下滾動的時候,有些元素會產(chǎn)生細(xì)小的動畫效果希柿。雖然動畫比較小诊沪,但卻能吸引瀏覽者的注意,使頁面更吸人眼球曾撤。
--- WOW.js 依賴animate.css端姚,所以它支持 animate.css 多種的動畫效果,能滿足各種需求挤悉。
--- IE6渐裸、IE7 等老舊瀏覽器不支持 CSS3 動畫,所以沒有效果;而 wow.js 也使用了 querySelectorAll 方法昏鹃,IE 低版本會報(bào)錯尚氛。為了達(dá)到更好的兼容,最好加一個瀏覽器及版本判斷洞渤。
使用方法:
1阅嘶、引入文件
<link rel="stylesheet" href="css/animate.min.css">
2、HTML
<div class="wow slideInLeft"></div>
<div class="wow slideInRight"></div>
可以加入 data-wow-duration(動畫持續(xù)時間)和 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’需要執(zhí)行動畫的元素的 class
?? ?animateClass: 'animated', //‘a(chǎn)nimated’animation.css 動畫的 class
?? ?offset: 0, //0距離可視區(qū)域多少開始執(zhí)行動畫
?? ?mobile: true, //true是否在移動設(shè)備上執(zhí)行動畫
?? ?live: true //true異步加載的內(nèi)容是否有效
});
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>
這樣就有了一個可以自己發(fā)揮的動畫效果了护昧。
就是一個比較方便的進(jìn)入 或者 滾動 的時候的頁面的加載動畫了磷杏,可以隨意加入自己想要的動畫。
animate.css也可以與別的插件結(jié)合使用 比如 fullpage.js都是可以有這種頁面進(jìn)入 滾動時候加入動畫的效果捏卓。
fullpage.js與animate.css實(shí)現(xiàn)的動畫效果:
demo:
也是要引入相關(guān)文件 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');
}
}
});
});
//跳轉(zhuǎn)到某一屏
function getNext(){
$.fn.fullpage.moveTo(3);
}
//沒有動畫的跳轉(zhuǎn)到首屏
function getTop(){
$.fn.fullpage.silentMoveTo(1);
}
</script>
這樣的話 也有和wow.js類似的效果
都是頁面進(jìn)入 和 滾動時候 給元素加入動畫效果极祸。