pull-zoom-image.uvue 4.3 KB
Newer Older
1 2 3 4 5
<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"
6 7
     refresher-default-style="none" @refresherpulling="onRefresherpulling"
     :refresher-threshold="300" :refresher-max-drag-distance="299">
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

    <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
        $INodeMap: new Map<string, INode>()
40 41
      }
    },
42 43 44 45 46 47
    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})`)
48 49 50
      },
      // 工具方法,用于快速设置 INode 的 style
      setINodeStyle(refName : string, propertyName : string, propertyStyle : any) : void {
51 52 53 54 55
        let iNode : INode | null = this.$INodeMap.get(refName)
        if (iNode == null) {
          iNode = this.$refs.get(refName) as INode;
          this.$INodeMap.set(refName, iNode)
        }
56
        iNode.style.setProperty(propertyName, propertyStyle);
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
      },
      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>
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
  .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;
91 92 93
  }

  .body {
94
    margin-top: -200px;
95
    width: 750rpx;
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  }

  .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;
129 130 131 132 133 134 135 136 137
    padding: 15px;
  }

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

140
  .item-content {
141
    background-color: #fff;
142 143
    margin: 0 5px;
    padding: 10px;
144
    border-radius: 5px;
145 146
    border: 1px solid rgba(220, 220, 220, 0.3);
  }
147

148
  .item-content-text {
149
    font-size: 14px;
150 151 152 153 154 155
    color: #666;
    line-height: 20px;
  }

  .nav-back {
    position: absolute;
156 157
    top: 30px;
    left: 10px;
158 159 160 161 162 163 164 165 166 167 168 169 170 171
    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>