一、单独页面分开调用
index.wxml
<scroll-view scroll-y style='height:{{scroll_height}}rpx;background-color: #f2f2f2;'> </scroll-view>
index.js
Page({
data: {
scroll_height: 0,
},
onLoad: function() {
let windowHeight = wx.getSystemInfoSync().windowHeight // 屏幕的高度
let windowWidth = wx.getSystemInfoSync().windowWidth // 屏幕的宽度
this.setData({
scroll_height: windowHeight * 750 / windowWidth
})
},
})
二、在小程序中写成公用方法
index.wxml
<scroll-view scroll-y style='height:{{scroll_height}}rpx;background-color: #f2f2f2;'> </scroll-view>
index.js
Page({
data: {
scroll_height: 0,
},
onLoad: function() { // 获取页面高度,设置背景色
var that = this;
app.scrollHeight(that);
},
})
app.js
scrollHeight: function(that) { // 获取页面高度,设置背景色,公用方法
let windowHeight = wx.getSystemInfoSync().windowHeight // 屏幕的高度
let windowWidth = wx.getSystemInfoSync().windowWidth // 屏幕的宽度
that.setData({
scroll_height: windowHeight * 750 / windowWidth
})
},
隐藏滚动条
::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
}
网友评论