Last active
January 8, 2019 05:18
-
-
Save 1c7/626344b058c08fc82e96664b18145884 to your computer and use it in GitHub Desktop.
微信小程序代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Page({ | |
data: { | |
offsetY: 0, | |
}, | |
onShow(){ | |
this.get_image_offset(); | |
}, | |
get_image_offset(){ | |
if(this.data.offsetY == 0){ | |
var that = this; | |
var query = wx.createSelectorQuery(); | |
query.select('.image_show').boundingClientRect(function (rect) { | |
if (rect != undefined && rect != null && rect.top != undefined){ | |
var top = rect.top | |
console.log(top); | |
// 因页面滚动,有时候 top 可能是负数,比如 -164 | |
// 从"标签添加页"进入"写文字页"再回来可能就有这样的问题 | |
if (top > 0){ | |
that.setData({ | |
offsetY: top | |
}) | |
} | |
} | |
}).exec(); | |
} | |
}, | |
// <image class='image_show' src="x" bind:tap='click_image' mode='widthFix'> | |
click_image(e) { | |
var p = { | |
x: e.detail.x, | |
y: e.detail.y, | |
show: true, | |
} | |
if(this.data.offsetY != 0){ | |
p.y = p.y - this.data.offsetY; | |
} | |
this.setData(p) | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://1c7.me/2019-1-1-wechat-miniapp-customize-navigationbar/