pull-zoom-image.uvue 4.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<template>
  <view @click="back" class="nav-back">
    <image class="back-img" src="/static/template/scroll-fold-nav/back.png" mode="widthFix"></image>
  </view>
  <scroll-view :scroll-y="true" style="flex:1;" :refresher-enabled="true"
    :refresher-triggered="refresherTriggered" refresher-default-style="none" @refresherpulling="onRefresherpulling"
    @refresherrefresh="onRefresherrefresh" :refresher-threshold="300">

    <view class="head-img-box">
      <image class="head-img-2" ref="head-img-2" src="../../../static/template/pull-zoom-image/head-img.jpg" mode="scaleToFill"></image>
    </view>
    <view class="body">
      <view class="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>
      </view>
      <view class="list-item" v-for="(item,index) in 30" :key="index" :class="{'last-list-item':index == 29}">
        <view class="item-content">
          <text class="item-content-text" style="padding-left: 4px;">{{item}}. 占位</text>
        </view>
      </view>
    </view>

    <view slot="refresher">
      <view class="head-img-box">
        <image class="head-img-1" ref="head-img-1" src="../../../static/template/pull-zoom-image/head-img.jpg" mode="scaleToFill"></image>
      </view>
    </view>
  </scroll-view>
33 34
</template>

35
<script>
36 37 38
  export default {
    data() {
      return {
39 40 41
        $INodeMap: new Map<string, INode>(),

        refresherTriggered: false,
42 43
      }
    },
44 45 46 47 48 49
    methods: {
      onRefresherpulling(e : RefresherEvent) {
        // console.log('onRefresherpulling',e.detail.dy)
        let pullingDistance:number = e.detail.dy
        this.setINodeStyle("head-img-1", 'transform', `scale(${pullingDistance / 200 + 1})`)
        this.setINodeStyle("head-img-2", 'transform', `scale(${pullingDistance / 200 + 1})`)
50
      },
51 52 53 54 55 56
      onRefresherrefresh() {
        this.refresherTriggered = true
        //拖动结束
        setTimeout(() => {
          this.refresherTriggered = false
        }, 0)
57
      },
58 59 60 61 62
      getINodeByRefName(refName : string) : INode {
        let iNode : INode | null = this.$INodeMap.get(refName)
        if (iNode == null) {
          iNode = this.$refs.get(refName) as INode;
          this.$INodeMap.set(refName, iNode)
63
        }
64
        return iNode
65 66 67
      },
      // 工具方法,用于快速设置 INode 的 style
      setINodeStyle(refName : string, propertyName : string, propertyStyle : any) : void {
68 69
        let iNode = this.getINodeByRefName(refName)
        iNode?.style?.setProperty(propertyName, propertyStyle);
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
      },
      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>
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  .head-img-box {
    position: relative;
    height: 300px;
  }
  .head-img-1,.head-img-2{
    position: absolute;
    left: -125rpx;
    width: 1000rpx;
    height: 600px;
  }
  .head-img-1 {
    top: 0;
  }
  .head-img-2 {
    bottom: 0;
104 105 106
  }

  .body {
107
    margin-top: -200px;
108
    width: 750rpx;
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  }

  .user-info {
    padding: 15px;
    flex-direction: row;
  }

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

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

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

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

  .content {
    background-color: #FFF;
    border-radius: 10px;
142 143 144 145 146 147 148 149 150
    padding: 15px;
  }

  .list-item {
    background-color: #FFF;
    padding-top: 15px;
  }
  .last-list-item{
    padding-bottom: 15px;
151 152
  }

153
  .item-content {
154
    background-color: #fff;
155 156
    margin: 0 5px;
    padding: 10px;
157
    border-radius: 5px;
158 159
    border: 1px solid rgba(220, 220, 220, 0.3);
  }
160

161
  .item-content-text {
162
    font-size: 14px;
163 164 165 166 167 168
    color: #666;
    line-height: 20px;
  }

  .nav-back {
    position: absolute;
169 170
    top: 30px;
    left: 10px;
171 172 173 174 175 176 177 178 179 180 181 182 183 184
    background-color: rgba(220, 220, 220, 0.3);
    border-radius: 100px;
    width: 28px;
    height: 28px;
    justify-content: center;
    align-items: center;
    z-index: 10;
  }

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