W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
在應用中很多開發(fā)者都會用到頁面切換操作,BlendUI提供了相關(guān)頁面切換接口供開發(fā)者使用。
document.addEventListener("blendready", function () {
Blend.ui.layerInit("0", function (dom) {
$('#jump', dom).click(function (e) {
new Blend.ui.Layer({
"id": "contentLayerId",
"url": "content.html",
"active": true,
"duration": 200
});
});
});
Blend.ui.layerInit("contentLayerId", function (dom) {
$('#nav-back', dom).click(function (e) {
Blend.ui.get('contentLayerId').out();
});
});
});
(1) 在主頁index.html
上添加一個Button
,定義一個頁面創(chuàng)建事件,事件中通過Layer方法實現(xiàn)了content.html
頁面初始化并跳轉(zhuǎn)。部分代碼如下:document.addEventListener("blendready", function () {
Blend.ui.layerInit("0", function (dom) {
$('#jump', dom).click(function (e) {
new Blend.ui.Layer({
"id": "contentLayerId",
"url": "content.html",
"active": true,
"duration": 200
});
});
});
});
(2) 在代碼中使用
Blend.ui.layerInit
方法定義了index.html
頁面初始化后的操作,layerInit
第一個參數(shù)代表頁面的id(默認首頁id為“0”)。
content.html
頁面上添加回退按鈕id:nav-back
,當觸發(fā)回退操作時,使用Blend.ui
中get
方法找到Layer實例,鏈式調(diào)用out
方法實現(xiàn)頁面回退操作。部分代碼如下:document.addEventListener("blendready", function () {
Blend.ui.layerInit("0", function (dom) {
$('#jump', dom).click(function (e) {
new Blend.ui.Layer({
"id": "contentLayerId",
"url": "content.html",
"active": true,
"duration": 200
});
});
});
Blend.ui.layerInit("contentLayerId", function (dom) {
$('#nav-back', dom).click(function (e) {
Blend.ui.get('contentLayerId').out();
});
});
});
代碼中同樣使用
layerInit
方法對id為contentLayerId
的content.html
頁面進行了回退按鈕綁定操作,定義了觸發(fā)back
回退事件,使用Layer.out()
方法實現(xiàn)頁面回退操作。
回退效果與out()方法效果相同,但是頁面回退的同時將會對當前頁面實例進行銷毀操作,下次頁面跳轉(zhuǎn)時頁面需要再次創(chuàng)建頁面實例?;菊{(diào)用方式同out(),此處不再多余解釋,部分代碼如下:
document.addEventListener("blendready", function () {
Blend.ui.layerInit("0", function (dom) {
$('#jump', dom).click(function (e) {
new Blend.ui.Layer({
"id": "contentLayerId",
"url": "content.html",
"active": true,
"duration": 200
});
});
});
Blend.ui.layerInit("contentLayerId", function (dom) {
$('#nav-back', dom).click(function (e) {
//僅此處與上一節(jié)的out()方法調(diào)用不同
Blend.ui.get('contentLayerId').destroy();
});
});
});
回退操作既可以使用Layer中的方法也可以直接使用Blend.ui中的方法。layerBack()方法可以實現(xiàn)根據(jù)頁面id進行頁面回退控制。部分代碼如下:
document.addEventListener("blendready", function () {
Blend.ui.layerInit("0", function (dom) {
$('#jump', dom).click(function (e) {
new Blend.ui.Layer({
"id": "contentLayerId",
"url": "content.html",
"active": true,
"duration": 200
});
});
});
Blend.ui.layerInit("contentLayerId", function (dom) {
$('#nav-back', dom).click(function (e) {
//回退操作
Blend.ui.layerBack();
//Blend.ui.layerBack("退至其他頁面id");
});
});
});
溫馨提示:使用該方法可以不再受到Layer句柄的約束,直接通過id進行頁面控制。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: