ionic list上拉全屏显示,下拉恢复

马上要给伟大的祖国母亲庆生了,也没有什么心情工作了,O(∩_∩)O哈哈~ 简单整理下这两天研究的东西,小弟学识浅薄,只是实现了效果,不知道还有没有其他的办法。
最近项目需求,简单实现了下ion-list上拉时将页面全屏显示,下拉恢复(也可以在上拉到顶部时恢复)。

因为页面需要在列表处可以进行拖拽,前期做这个项目的时候也是刚刚接触phonegap,就把ion-content放在了对应列表的地方,在上部就用div来显示一些信息。
不方便上源码,这里简单写一下吧, 纯手写啊。。。

html:

<div style="width:100%;" ng-class="{true:'detection-info-hide',false:'detection-info-show'}[detection_info_is_show]">
    <!-- 下面的overflow一定要写,再有内层的话也要加这个属性 -->
    <div style="overflow:hidden;">
        <!-- 这里是页面上部显示的内容,显示一些信息 -->
    </div>
</div>
<ion-content style="margin-top:220px;" ng-class="{true:'list-margin-sub',false:'list-margin-add'}[detection_info_is_show]">
    <ion-list ng-repeat="..." on-swipe-up="swipeUp()" on-swipe-down="swipeDown()" on-drag-up="swipeUp()" on-drag-down="swipeDown()">
        <div>
            <!-- 这里是列表项 -->
        </div>
    </ion-list>

</ion-content>

css 命名简单命名的,不要介意:

    .detection-info-hide{
        -webkit-animation:myfirst 0.5s;
        animation-fill-mode:forwards;
    }
    @-webkit-keyframes myfirst /* Safari and Chrome */
    {
        from   {
            height: 137px;}
        to  {
            height: 0px;}
    }

    .detection-info-show{
        -webkit-animation:mysecond 0.5s;
        animation-fill-mode:forwards;
    }
    @-webkit-keyframes mysecond /* Safari and Chrome */
    {
        from   {
            height: 0px;}
        to  {
            height: 137px;}
    }
    .list-margin-sub {
        -webkit-animation: list-margin-sub-sub 0.5s;
        animation-fill-mode:forwards;
    }
    @-webkit-keyframes list-margin-sub-sub {
        from   {
            margin-top: 220px;}
        to  {
            margin-top: 83px;}
    }
    .list-margin-add {
        -webkit-animation: list-margin-add-add 0.5s;
        animation-fill-mode:forwards;
    }
    @-webkit-keyframes list-margin-add-add {
        from   {
            margin-top: 83px;}
        to  {
            margin-top: 220px;}
    }

js:

$scope.swipeUp = function(){
            if(!$scope.has_excange_above){
                // 判断当前是否有滚动条,没有时上拉不隐藏
                if($ionicScrollDelegate.getScrollView().getScrollMax().top > $ionicScrollDelegate.getScrollPosition().top){
                    // 隐藏
                    $scope.detection_info_is_show = true;
                    $scope.scrollHeight = false;
                    $scope.has_excange_above = true;
                    $scope.has_excange_bottom = false;
                    // 滚动视图重新计算它的容器大小
                    // 时间根据animation的时间定的                    
                    $timeout(function(){$ionicScrollDelegate.resize()},550);
                }
            }
        }
        $scope.swipeDown = function(){
            if(!$scope.has_excange_bottom){          
                // 显示
                $scope.detection_info_is_show = false;
                $scope.scrollHeight = true;
                $scope.has_excange_above = false;
                $scope.has_excange_bottom = true;
            }
        }
大概就是上面的代码啦

实现的思路就是捕获angularjs的上拉、下拉、上滑、下滑事件,在这个事件上将咱们的样式添加上。 

实现起来有个问题,当快速上拉时,ion-list 生成的<div class="scroll">会脱离底部,慢慢拉的话没有这个问题。所以就在js里面加了一个resize,用来重新计算大小,别忘了添加$ionicScrollDelegate依赖。
PS:上面这个问题感觉没用太好,不知道是否有高人指点一二。小弟感激不尽。

另外,感觉这个效果不是很好,模仿淘宝的app做的,觉得可以在上拉的时候控制list不滚动,只做全屏操作,当全屏后,再上拉,list再跟着动,但是没有实现,思路是想拦截list的滚动事件,但是看源码好像是设置是否滚动后就不能改变了,再次请高人指点。
告退~准备放假了 祝祖国生日快乐
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
在Angular2移动端中实现上拉加载和下拉刷新的方式有许多种。下面我将介绍一种常用的实现方法。 1. 首先,我们需要引入一些必要的库和组件。我们可以使用Ionic框架中提供的IonRefresher和InfiniteScroll组件来实现下拉刷新和上拉加载的效果。需要确保已经安装了Ionic框架并引入了相关的模块。 2. 在需要实现上拉加载的页面或组件中,添加一个IonRefresher组件,并绑定事件。例如: ```html <ion-content> <ion-refresher (ionRefresh)="doRefresh($event)"> <ion-refresher-content></ion-refresher-content> </ion-refresher> <!--其他内容--> </ion-content> ``` 在组件中,定义一个doRefresh方法来处理刷新的逻辑。例如: ```typescript import { Component } from '@angular/core'; @Component({ selector: 'your-component', templateUrl: 'your-component.html', styleUrls: ['your-component.css'] }) export class YourComponent { doRefresh(event) { // 执行刷新逻辑 // 更新数据 // 结束刷新动作 event.complete(); } } ``` 3. 接下来,我们来实现上拉加载的效果。在页面或组件中添加一个InfiniteScroll组件,并绑定事件。例如: ```html <ion-content (ionInfinite)="loadMore($event)"> <!--其他内容--> <ion-infinite-scroll> <ion-infinite-scroll-content></ion-infinite-scroll-content> </ion-infinite-scroll> </ion-content> ``` 在组件中,定义一个loadMore方法来处理加载更多的逻辑。例如: ```typescript import { Component } from '@angular/core'; @Component({ selector: 'your-component', templateUrl: 'your-component.html', styleUrls: ['your-component.css'] }) export class YourComponent { loadMore(event) { // 执行加载更多逻辑 // 加载更多数据 // 结束加载更多动作 event.complete(); } } ``` 以上就是使用Ionic框架中的IonRefresher和InfiniteScroll组件来实现Angular2移动端上拉加载和下拉刷新的步骤。需注意在具体的业务逻辑中,需要结合实际情况进行相应的处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

freedomSure

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值