pull-zoom-image.uvue 4.6 KB
Newer Older
1 2 3 4
<template>
  <view @click="back" class="nav-back">
    <image class="back-img" src="/static/template/pull-zoom-image/back.png" mode="widthFix"></image>
  </view>
雪洛's avatar
雪洛 已提交
5
  <scroll-view style="flex:1;" :refresher-enabled="true"
6
    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

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

34 35 36 37 38 39 40
  </scroll-view>
</template>

<script>
  export default {
    data() {
      return {
A
Anne_LXM 已提交
41
        $elementMap: new Map<string, UniElement>()
42 43
      }
    },
44 45 46 47 48 49 50 51 52 53 54 55
    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
雪洛's avatar
雪洛 已提交
56
        this.setElementStyle("user-info", "transform", `translate(${x}px, ${y + (s-1)* -50}px) scale(${s})`)
DCloud_JSON's avatar
DCloud_JSON 已提交
57
        this.setElementStyle("head-img-box-2", "transform", `translateY(${y}px)`)
58 59 60
      },
      onRefresherpulling(e : RefresherEvent) {
        // console.log('onRefresherpulling',e.detail.dy)
61
        let pullingDistance : number = e.detail.dy
62 63 64 65 66
        this.setElementStyle("head-img-1", 'transform', `scale(${pullingDistance / 200 + 1})`)
        this.setElementStyle("head-img-2", 'transform', `scale(${pullingDistance / 200 + 1})`)
      },
      // 工具方法,用于快速设置 Element 的 style
      setElementStyle(refName : string, propertyName : string, propertyStyle : any) : void {
A
Anne_LXM 已提交
67
        let element : UniElement | null = (this.$data['$elementMap'] as Map<string, UniElement>).get(refName)
DCloud_JSON's avatar
DCloud_JSON 已提交
68
        if (element == null) {
DCloud-yyl's avatar
DCloud-yyl 已提交
69
          element = this.$refs[refName] as UniElement;
A
Anne_LXM 已提交
70
          (this.$data['$elementMap'] as Map<string, UniElement>).set(refName, element)
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
        }
        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>
92 93 94
  .head-img-box-1,
  .head-img-box-2
  {
95 96
    position: relative;
    height: 300px;
97
  }
98 99 100 101

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

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

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

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

  .user-info{
    margin-top: -110px;
    width: 750rpx;
    padding: 15px;
125
    flex-direction: row;
126 127 128 129
    z-index: 10;
  }

  .user-info .user-avatar {
H
hdx 已提交
130 131
    width: 75px;
    height: 75px;
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    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;
  }

152 153 154 155

  .list-box {
    background-color: #FFF;
    z-index: 1;
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 185 186

  .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;
  }
187
</style>