pull-zoom-image.uvue 4.6 KB
Newer Older
1 2 3 4 5 6
<template>
  <view @click="back" class="nav-back">
    <image class="back-img" src="/static/template/pull-zoom-image/back.png" mode="widthFix"></image>
  </view>
  <scroll-view :scroll-y="true" style="flex:1;" :refresher-enabled="true"
    refresher-default-style="none" @refresherpulling="onRefresherpulling"
7 8
    :refresher-threshold="300" :refresher-max-drag-distance="299"
    @scroll="onScroll" :rebound="false"
9
    >
10 11
    <view class="head-img-box-2" ref="head-img-box-2">
      <image class="img" ref="head-img-2" src="../../../static/template/pull-zoom-image/head-img.jpg" mode="scaleToFill"></image>
12 13 14 15 16 17 18
    </view>
    <view class="user-info" ref="user-info">
      <image class="user-avatar" src="../../../static/test-image/logo.png" mode="widthFix"></image>
      <view class="font-box">
        <text class="username">uni-app-x</text>
        <text class="slogan">一次开发,多端覆盖</text>
      </view>
19 20 21 22 23 24
    </view>
    <view class="list-box">
      <view class="item" v-for="(item,index) in 30" :key="index">
        <text class="text">{{item}}. 占位</text>
      </view>
    </view>
25

26
    <view slot="refresher">
27
      <view class="head-img-box-1">
DCloud-yyl's avatar
DCloud-yyl 已提交
28
        <image class="img" ref="head-img-1" src="/static/template/pull-zoom-image/head-img.jpg" mode="scaleToFill"></image>
29
      </view>
30 31
    </view>

32 33 34 35 36 37 38
  </scroll-view>
</template>

<script>
  export default {
    data() {
      return {
雪洛's avatar
雪洛 已提交
39
        $elementMap: new Map<string, UniElement>()
40 41
      }
    },
42 43 44 45 46 47 48 49 50 51 52 53
    methods: {
      onScroll(e : ScrollEvent) {
        const {scrollTop} = e.detail
        let y : number = scrollTop - 110
        let s : number = (100 - scrollTop/3)/100
        if(y < 0){
          y = 0
        }
        if(s < 0.7){
          s = 0.7
        }
        let x : number = (1 - s) * -100
DCloud_JSON's avatar
DCloud_JSON 已提交
54 55
        this.setElementStyle("user-info", "transform", `translate(${x},${y + (s-1)* -50}px) scale(${s})`)
        this.setElementStyle("head-img-box-2", "transform", `translateY(${y}px)`)
56 57 58
      },
      onRefresherpulling(e : RefresherEvent) {
        // console.log('onRefresherpulling',e.detail.dy)
59
        let pullingDistance : number = e.detail.dy
60 61 62
        this.setElementStyle("head-img-1", 'transform', `scale(${pullingDistance / 200 + 1})`)
        this.setElementStyle("head-img-2", 'transform', `scale(${pullingDistance / 200 + 1})`)
      },
雪洛's avatar
雪洛 已提交
63
      // 工具方法,用于快速设置 UniElement 的 style
64
      setElementStyle(refName : string, propertyName : string, propertyStyle : any) : void {
雪洛's avatar
雪洛 已提交
65
        let element : UniElement | null = (this.$data['$elementMap'] as Map<string, UniElement>).get(refName)
DCloud_JSON's avatar
DCloud_JSON 已提交
66
        if (element == null) {
雪洛's avatar
雪洛 已提交
67 68
          element = this.$refs[refName] as UniElement;
          (this.$data['$elementMap'] as Map<string, UniElement>).set(refName, element)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
        }
        element.style.setProperty(propertyName, propertyStyle);
      },
      back() {
        uni.navigateBack({
          success(result) {
            console.log('navigateBack success', result.errMsg)
          },
          fail(error) {
            console.log('navigateBack fail', error.errMsg)
          },
          complete(result) {
            console.log('navigateBack complete', result.errMsg)
          }
        })
      }
    }
  }
</script>

<style>
90 91 92
  .head-img-box-1,
  .head-img-box-2
  {
93 94
    position: relative;
    height: 300px;
95
  }
96 97 98 99

  .head-img-box-1 .img,
  .head-img-box-2 .img
  {
100 101 102 103 104
    position: absolute;
    left: -125rpx;
    width: 1000rpx;
    height: 600px;
  }
105 106

  .head-img-box-1 .img {
107 108
    top: 0;
  }
109 110 111 112 113 114 115 116

  .head-img-box-2 .img {
    bottom: -100;
  }

  .head-img-box-2 {
    z-index: 9;
    height: 200px;
117 118 119 120 121 122
  }

  .user-info{
    margin-top: -110px;
    width: 750rpx;
    padding: 15px;
123
    flex-direction: row;
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    z-index: 10;
  }

  .user-info .user-avatar {
    width: 150rpx;
    height: 150rpx;
    border-radius: 100px;
    border: 3px solid #FFF;
  }

  .user-info .font-box {
    flex-direction: column;
    justify-content: space-around;
    padding: 10px;
  }

  .user-info .username {
    font-size: 26px;
    color: #FFF;
  }

  .user-info .slogan {
    font-size: 16px;
    color: #FFF;
  }

150 151 152 153

  .list-box {
    background-color: #FFF;
    z-index: 1;
154
  }
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

  .list-box .item {
    padding: 10px;
    margin: 5px;
    border-radius: 5px;
    border: 1px solid rgba(220, 220, 220, 0.3);
  }

  .list-box .text {
    font-size: 14px;
    color: #666;
    line-height: 20px;
  }

  .nav-back {
    position: absolute;
    top: 30px;
    left: 10px;
    border-radius: 100px;
    width: 28px;
    height: 28px;
    justify-content: center;
    align-items: center;
    z-index: 10;
  }

  .nav-back .back-img {
    width: 18px;
    height: 18px;
  }
185
</style>