提交 78c9d2af 编写于 作者: DCloud_JSON's avatar DCloud_JSON

更新 示例项目 pull-zoom-image 向上滚动超过100px后固定头部

上级 592ce0dd
<template> <template>
<view @click="back" class="nav-back"> <view @click="back" class="nav-back">
<image class="back-img" src="/static/template/scroll-fold-nav/back.png" mode="widthFix"></image> <image class="back-img" src="/static/template/pull-zoom-image/back.png" mode="widthFix"></image>
</view> </view>
<scroll-view :scroll-y="true" style="flex:1;" :refresher-enabled="true" <scroll-view :scroll-y="true" style="flex:1;" :refresher-enabled="true"
refresher-default-style="none" @refresherpulling="onRefresherpulling" refresher-default-style="none" @refresherpulling="onRefresherpulling"
:refresher-threshold="300" :refresher-max-drag-distance="299"> :refresher-threshold="300" :refresher-max-drag-distance="299"
@scroll="onScroll" :rebound="false"
<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 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>
</view> </view>
<view class="body"> <view class="user-info" ref="user-info">
<view class="user-info"> <image class="user-avatar" src="../../../static/test-image/logo.png" mode="widthFix"></image>
<image class="user-avatar" src="../../../static/test-image/logo.png" mode="widthFix"></image> <view class="font-box">
<view class="font-box"> <text class="username">uni-app-x</text>
<text class="username">uni-app-x</text> <text class="slogan">一次开发,多端覆盖</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> </view>
<view class="list-box">
<view class="item" v-for="(item,index) in 30" :key="index">
<text class="text">{{item}}. 占位</text>
</view>
</view>
<view slot="refresher"> <view slot="refresher">
<view class="head-img-box"> <view class="head-img-box-1">
<image class="head-img-1" ref="head-img-1" src="../../../static/template/pull-zoom-image/head-img.jpg" mode="scaleToFill"></image> <image class="img" ref="head-img-1" src="../../../static/template/pull-zoom-image/head-img.jpg" mode="scaleToFill"></image>
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
</template> </template>
...@@ -39,10 +39,24 @@ ...@@ -39,10 +39,24 @@
$INodeMap: new Map<string, INode>() $INodeMap: new Map<string, INode>()
} }
}, },
methods: { 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
this.setINodeStyle("user-info", "transform", `translate(${x},${y + (s-1)* -50}px) scale(${s})`)
this.setINodeStyle("head-img-box-2", "transform", `translateY(${y}px)`)
},
onRefresherpulling(e : RefresherEvent) { onRefresherpulling(e : RefresherEvent) {
// console.log('onRefresherpulling',e.detail.dy) // console.log('onRefresherpulling',e.detail.dy)
let pullingDistance:number = e.detail.dy let pullingDistance : number = e.detail.dy
this.setINodeStyle("head-img-1", 'transform', `scale(${pullingDistance / 200 + 1})`) this.setINodeStyle("head-img-1", 'transform', `scale(${pullingDistance / 200 + 1})`)
this.setINodeStyle("head-img-2", 'transform', `scale(${pullingDistance / 200 + 1})`) this.setINodeStyle("head-img-2", 'transform', `scale(${pullingDistance / 200 + 1})`)
}, },
...@@ -73,79 +87,80 @@ ...@@ -73,79 +87,80 @@
</script> </script>
<style> <style>
.head-img-box { .head-img-box-1,
.head-img-box-2
{
position: relative; position: relative;
height: 300px; height: 300px;
} }
.head-img-1,.head-img-2{
.head-img-box-1 .img,
.head-img-box-2 .img
{
position: absolute; position: absolute;
left: -125rpx; left: -125rpx;
width: 1000rpx; width: 1000rpx;
height: 600px; height: 600px;
} }
.head-img-1 {
.head-img-box-1 .img {
top: 0; top: 0;
} }
.head-img-2 {
bottom: 0; .head-img-box-2 .img {
bottom: -100;
}
.head-img-box-2 {
z-index: 9;
height: 200px;
} }
.body { .user-info{
margin-top: -200px; margin-top: -110px;
width: 750rpx; width: 750rpx;
}
.user-info {
padding: 15px; padding: 15px;
flex-direction: row; flex-direction: row;
z-index: 10;
} }
.user-avatar { .user-info .user-avatar {
width: 150rpx; width: 150rpx;
height: 150rpx; height: 150rpx;
border-radius: 100px; border-radius: 100px;
border: 3px solid #FFF; border: 3px solid #FFF;
} }
.font-box { .user-info .font-box {
flex-direction: column; flex-direction: column;
justify-content: space-around; justify-content: space-around;
padding: 10px; padding: 10px;
} }
.username { .user-info .username {
font-size: 26px; font-size: 26px;
color: #FFF; color: #FFF;
} }
.slogan { .user-info .slogan {
font-size: 16px; font-size: 16px;
color: #FFF; color: #FFF;
} }
.content {
background-color: #FFF; .list-box {
border-radius: 10px; background-color: #FFF;
padding: 15px; z-index: 1;
}
.list-item {
background-color: #FFF;
padding-top: 15px;
} }
.last-list-item{
padding-bottom: 15px;
}
.item-content { .list-box .item {
background-color: #fff;
margin: 0 5px;
padding: 10px; padding: 10px;
margin: 5px;
border-radius: 5px; border-radius: 5px;
border: 1px solid rgba(220, 220, 220, 0.3); border: 1px solid rgba(220, 220, 220, 0.3);
} }
.item-content-text { .list-box .text {
font-size: 14px; font-size: 14px;
color: #666; color: #666;
line-height: 20px; line-height: 20px;
...@@ -155,7 +170,6 @@ ...@@ -155,7 +170,6 @@
position: absolute; position: absolute;
top: 30px; top: 30px;
left: 10px; left: 10px;
background-color: rgba(220, 220, 220, 0.3);
border-radius: 100px; border-radius: 100px;
width: 28px; width: 28px;
height: 28px; height: 28px;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册