pull-zoom-image.uvue 4.6 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
        $INodeMap: new Map<string, INode>(),
        refresherTriggered: false,
41 42
      }
    },
43 44 45 46 47 48
    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})`)
49
      },
50 51 52 53 54 55
      onRefresherrefresh() {
        this.refresherTriggered = true
        //拖动结束
        setTimeout(() => {
          this.refresherTriggered = false
        }, 0)
56
      },
57
      getINode(refName : string) : INode {
58 59 60 61
        let iNode : INode | null = this.$INodeMap.get(refName)
        if (iNode == null) {
          iNode = this.$refs.get(refName) as INode;
          this.$INodeMap.set(refName, iNode)
62
        }
63
        return iNode
64 65 66
      },
      // 工具方法,用于快速设置 INode 的 style
      setINodeStyle(refName : string, propertyName : string, propertyStyle : any) : void {
67 68
        let iNode = this.getINode(refName)
        iNode.style.setProperty(propertyName, propertyStyle);
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
      },
      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>
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  .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;
103 104 105
  }

  .body {
106
    margin-top: -200px;
107
    width: 750rpx;
108 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
  }

  .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;
141 142 143 144 145 146 147 148 149
    padding: 15px;
  }

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

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

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

  .nav-back {
    position: absolute;
168 169
    top: 30px;
    left: 10px;
170 171 172 173 174 175 176 177 178 179 180 181 182 183
    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>