gpt4 book ai didi

angularjs - 如何为 ionic 中的嵌套标签栏添加幻灯片功能?

转载 作者:行者123 更新时间:2023-12-01 13:52:45 25 4
gpt4 key购买 nike

如果我们有六个选项卡,我如何为 ionic 框架中的嵌套选项卡栏添加滑动功能,所以我只希望六个选项卡中的三个选项卡显示在移动屏幕上,并且还可以向左或向右滑动到另一个选项卡?

我的 HTML 模板

<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

<title>Tabs Example</title>

<link href="//code.ionicframework.com/1.0.0-beta.12/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/1.0.0-beta.12/js/ionic.bundle.js"></script>
</head>

<body>

<ion-nav-bar class="nav-title-slide-ios7 bar-positive">
<ion-nav-back-button class="button-icon ion-arrow-left-c"></ion-nav-back-button>
</ion-nav-bar>

<ion-nav-view animation="slide-left-right"></ion-nav-view>

<script id="templates/tabs.html" type="text/ng-template">

<ion-tabs class="tabs-icon-top tabs-positive">

<ion-tab title="Home" icon="ion-home" ui-sref="tabs.home">
<ion-nav-view name="home-tab"></ion-nav-view>
</ion-tab>

<ion-tab title="About" icon="ion-ios7-information" ui-sref="tabs.about.page1">
<ion-nav-view name="about-tab"></ion-nav-view>
</ion-tab>

</ion-tabs>

</script>

<script id="templates/home.html" type="text/ng-template">

<ion-view title="Home">
<ion-content class="padding">
Please check about tab
</ion-content>
</ion-view>

</script>

<script id="templates/about.html" type="text/ng-template">

<ion-view title="About">


<ui-view name="about-page"></ui-view>

</ion-view>

</script>

<script id="templates/about-page1.html" type="text/ng-template">

<ion-view title="Page 1">
<div class="tabs-striped tabs-top tabs-background-light tabs-color-assertive">
<div class="tabs">
<a class="tab-item tab-item-active" ui-sref="tabs.about.page1">
Page 1
</a>
<a class="tab-item" ui-sref="tabs.about.page2">
Page 2
</a>
<a class="tab-item" ui-sref="tabs.about.page3">
Page 3
</a>
<a class="tab-item" ui-sref="tabs.about.page4">
Page 4 </a>
<a class="tab-item" ui-sref="tabs.about.page5">
Page 5
</a>
<a class="tab-item" ui-sref="tabs.about.page6">
Page 6
</a>
</div>
</div>
<ion-content class="padding has-tabs-top">
<p> Page 1</p>
</ion-content>
</ion-view>

</script>

<script id="templates/about-page2.html" type="text/ng-template">

<ion-view title="Page 2">
<div class="tabs-striped tabs-top tabs-background-light tabs-color-assertive">
<div class="tabs">
<a class="tab-item" ui-sref="tabs.about.page1">
Page 1
</a>
<a class="tab-item tab-item-active" ui-sref="tabs.about.page2">
Page 2
</a>
<a class="tab-item" ui-sref="tabs.about.page3">
Page 3
</a>
<a class="tab-item" ui-sref="tabs.about.page4">
Page 4 </a>
<a class="tab-item" ui-sref="tabs.about.page5">
Page 5
</a>
<a class="tab-item" ui-sref="tabs.about.page6">
Page 6
</a>
</div>
</div>
<ion-content class="padding has-tabs-top">
<p> Page 2</p>
</ion-content>
</ion-view>

</script>

</body>
</html>

有关完整的源代码,请查看我关于 codepen 上的嵌套标签栏的问题

注意:我只是在 codepen 中的示例代码中显示了六个嵌套选项卡栏中的两个嵌套选项卡栏。

最佳答案

您可以使用 Ionic 指令(例如 on-swipe、on-swipe-left 和 on-swipe-right)在选项卡之间滑动导航。这是我从你的代码笔上制作的一个例子。 http://codepen.io/anon/pen/bdLwPz

转到关于选项卡,然后单击并向左滑动。砰!魔法!
在此处阅读有关手势事件的更多信息:http://ionicframework.com/docs/api/directive/onSwipe/

这是 HTML:

<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

<title>Tabs Example</title>

<link href="//code.ionicframework.com/1.0.0-beta.12/css/ionic.css" rel="stylesheet">
<script src="//code.ionicframework.com/1.0.0-beta.12/js/ionic.bundle.js"></script>
</head>

<body ng-controller="main">

<ion-nav-bar class="nav-title-slide-ios7 bar-positive">
<ion-nav-back-button class="button-icon ion-arrow-left-c"></ion-nav-back-button>
</ion-nav-bar>

<ion-nav-view animation="slide-left-right"></ion-nav-view>

<script id="templates/tabs.html" type="text/ng-template">

<ion-tabs class="tabs-icon-top tabs-positive">

<ion-tab title="Home" icon="ion-home" ui-sref="tabs.home">
<ion-nav-view name="home-tab"></ion-nav-view>
</ion-tab>

<ion-tab title="About" icon="ion-ios7-information" ui-sref="tabs.about.page1">
<ion-nav-view name="about-tab" ></ion-nav-view>
</ion-tab>

</ion-tabs>

</script>

<script id="templates/home.html" type="text/ng-template">

<ion-view title="Home">
<ion-content class="padding">
Please check about tab
</ion-content>
</ion-view>

</script>

<script id="templates/about.html" type="text/ng-template">

<ion-view title="About">


<ui-view name="about-page"></ui-view>

</ion-view>

</script>

<script id="templates/about-page1.html" type="text/ng-template">

<ion-view title="Page 1">
<div class="tabs-striped tabs-top tabs-background-light tabs-color-assertive">
<div class="tabs">
<a class="tab-item tab-item-active" ui-sref="tabs.about.page1">
Page 1
</a>
<a class="tab-item" ui-sref="tabs.about.page2">
Page 2
</a>
<a class="tab-item" ui-sref="tabs.about.page3">
Page 3
</a>
<a class="tab-item" ui-sref="tabs.about.page4">
Page 4 </a>
<a class="tab-item" ui-sref="tabs.about.page5">
Page 5
</a>
<a class="tab-item" ui-sref="tabs.about.page6">
Page 6
</a>
</div>
</div>
<ion-content on-swipe-left="onSwipeLeft()" class="padding has-tabs-top">
<p> Page 1</p>
</ion-content>
</ion-view>

</script>

<script id="templates/about-page2.html" type="text/ng-template">

<ion-view title="Page 2">
<div class="tabs-striped tabs-top tabs-background-light tabs-color-assertive">
<div class="tabs">
<a class="tab-item" ui-sref="tabs.about.page1">
Page 1
</a>
<a class="tab-item tab-item-active" ui-sref="tabs.about.page2">
Page 2
</a>
<a class="tab-item" ui-sref="tabs.about.page3">
Page 3
</a>
<a class="tab-item" ui-sref="tabs.about.page4">
Page 4 </a>
<a class="tab-item" ui-sref="tabs.about.page5">
Page 5
</a>
<a class="tab-item" ui-sref="tabs.about.page6">
Page 6
</a>
</div>
</div>
<ion-content class="padding has-tabs-top">
<p> Page 2</p>
</ion-content>
</ion-view>

</script>

</body>
</html>

和JS:
angular.module('ionicApp', ['ionic'])

.config(function($stateProvider, $urlRouterProvider) {

$stateProvider

.state('tabs', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})

.state('tabs.home', {
url: "/home",
views: {
'home-tab': {
templateUrl: "templates/home.html",
}
}
})

.state('tabs.about', {
url: "/about",
abstract: true,
views: {
'about-tab': {
templateUrl: "templates/about.html"
}
}
})

.state('tabs.about.page1', {
url: "/page1",
views: {
'about-page': {
templateUrl: "templates/about-page1.html"
}
}
})

.state('tabs.about.page2', {
url: "/page2",
views: {
'about-page': {
templateUrl: "templates/about-page2.html"
}
}
});

$urlRouterProvider.otherwise("/tab/home");

})
.controller('main', function($scope, $state){

$scope.onSwipeLeft = function(){
$state.go('tabs.about.page2')
};

})

关于angularjs - 如何为 ionic 中的嵌套标签栏添加幻灯片功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31152201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com