IONIC下屏幕向上滑动时渐变显示隐藏的标题栏

要达到的效果:

在向上滑动屏幕时渐变显示原本隐藏的标题栏,向下滑动到某个位置时隐藏标题栏。


处理方法:

1、本想用指令来实现,以方便以后的重用,但是碰到几个坑。

2、指令行不通以后,才实现第二种,也是本文介绍的内容。


第一步:


  $scope.show=false;//控制标题栏是否显示
  $scope.transrate=0;//控制标题栏透明度
  $scope.getScrollPosition = function(){
    var position=$ionicScrollDelegate.getScrollPosition().top;//取滑动TOP值
    if (position<=40)//小于等于40像素时隐藏标题
    {
      $scope.transrate=0;
      $scope.show=false;
    }else if (position<=200){//大于40、小于200时显示标题栏,并设置透明度
      $scope.transrate=position/200;
      $scope.show=true;
    }else{
      $scope.transrate=1;
      $scope.show=true;
    }
    $scope.$apply();
  }

第二步:

修改HTML

<ion-view view-title="云商城" hide-nav-bar="true">
  <ion-header-bar align-title="center" class="bar-assertive" ng-if="show==true" style=" opacity: {{transrate}}">
    <a class="button button-clear" ng-click="gochat()"><i class="icon ion-ios-chatbubble-outline headericon" > </i></a>
    <h1 class="title">云商城</h1>
    <a class="button button-clear" ng-click="GoSearch()" style="width: 50px;"><i class="icon icon-uniE65C headericon" > </i></a>
  </ion-header-bar>
  <ion-content  class="mybody" no-tap-scroll="true"  on-scroll="getScrollPosition()">
<span style="white-space:pre">	</span>//略
<pre name="code" class="html">  </ion-content>

 




  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值