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>

(設(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.jsanimate.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)入 和 滾動時候 給元素加入動畫效果极祸。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市怠晴,隨后出現(xiàn)的幾起案子遥金,更是在濱河造成了極大的恐慌,老刑警劉巖蒜田,帶你破解...
    沈念sama閱讀 216,997評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件稿械,死亡現(xiàn)場離奇詭異,居然都是意外死亡冲粤,警方通過查閱死者的電腦和手機(jī)美莫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,603評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來梯捕,“玉大人厢呵,你說我怎么就攤上這事】耍” “怎么了襟铭?”我有些...
    開封第一講書人閱讀 163,359評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長短曾。 經(jīng)常有香客問我寒砖,道長,這世上最難降的妖魔是什么嫉拐? 我笑而不...
    開封第一講書人閱讀 58,309評論 1 292
  • 正文 為了忘掉前任哩都,我火速辦了婚禮,結(jié)果婚禮上婉徘,老公的妹妹穿的比我還像新娘漠嵌。我一直安慰自己璃赡,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,346評論 6 390
  • 文/花漫 我一把揭開白布献雅。 她就那樣靜靜地躺著碉考,像睡著了一般。 火紅的嫁衣襯著肌膚如雪挺身。 梳的紋絲不亂的頭發(fā)上侯谁,一...
    開封第一講書人閱讀 51,258評論 1 300
  • 那天,我揣著相機(jī)與錄音章钾,去河邊找鬼墙贱。 笑死,一個胖子當(dāng)著我的面吹牛贱傀,可吹牛的內(nèi)容都是我干的惨撇。 我是一名探鬼主播,決...
    沈念sama閱讀 40,122評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼府寒,長吁一口氣:“原來是場噩夢啊……” “哼魁衙!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起株搔,我...
    開封第一講書人閱讀 38,970評論 0 275
  • 序言:老撾萬榮一對情侶失蹤剖淀,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后纤房,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體纵隔,經(jīng)...
    沈念sama閱讀 45,403評論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,596評論 3 334
  • 正文 我和宋清朗相戀三年炮姨,在試婚紗的時候發(fā)現(xiàn)自己被綠了捌刮。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,769評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡舒岸,死狀恐怖绅作,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情吁津,我是刑警寧澤棚蓄,帶...
    沈念sama閱讀 35,464評論 5 344
  • 正文 年R本政府宣布堕扶,位于F島的核電站碍脏,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏稍算。R本人自食惡果不足惜典尾,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,075評論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望糊探。 院中可真熱鬧钾埂,春花似錦河闰、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,705評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至髓考,卻和暖如春部念,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背氨菇。 一陣腳步聲響...
    開封第一講書人閱讀 32,848評論 1 269
  • 我被黑心中介騙來泰國打工儡炼, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人查蓉。 一個月前我還...
    沈念sama閱讀 47,831評論 2 370
  • 正文 我出身青樓乌询,卻偏偏與公主長得像,于是被迫代替她去往敵國和親豌研。 傳聞我的和親對象是個殘疾皇子妹田,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,678評論 2 354

推薦閱讀更多精彩內(nèi)容