首页 >> js开发 >> js微信小程序实现吸顶特效js大全
js微信小程序实现吸顶特效js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
本文实例为大家分享了微信小程序实现吸顶特效的具体代码,供大家参考,具体内容如下效果图wxml代码:
食疗方法
动作方法
食疗方法
动作方法
wxss代码:
/* 吸顶开始 */
.xiding
{
width: 100%;
height: 30px;
background: white;
}
.title-1
{
text-align: center;
}
.title-2
{
text-align: center;
}
/* 吸顶 */
.Fixed
{
position: fixed;
top: 0;
z-index: 2;
}
/* 吸顶结束 */
/* 吸顶开始 */
.xiding
{
width: 100%;
height: 30px;
background: white;
}
.title-1
{
text-align: center;
}
.title-2
{
text-align: center;
}
/* 吸顶 */
.Fixed
{
position: fixed;
top: 0;
z-index: 2;
}
/* 吸顶结束 */wxjs代码:
oneFixed:"",
tabTop:"0",
// 吸顶动态监听函数
onPageScroll:function(event)
{
console.log(event.scrollTop > this.data.tabTop)
if(event.scrollTop>this.data.tabTop)
{
if(this.data.tabFix)
{
return
}
else{
this.setData({
oneFixed:"Fixed"//添加吸顶类
})
}
}
else
{
this.setData({
oneFixed:''
})
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let This=this;
const query=wx.createSelectorQuery();
query.select('#tab').boundingClientRect(function(res)
{
This.data.tabTop=res.top//255
}
).exec();
},
oneFixed:"",
tabTop:"0",
// 吸顶动态监听函数
onPageScroll:function(event)
{
console.log(event.scrollTop > this.data.tabTop)
if(event.scrollTop>this.data.tabTop)
{
if(this.data.tabFix)
{
return
}
else{
this.setData({
oneFixed:"Fixed"//添加吸顶类
})
}
}
else
{
this.setData({
oneFixed:''
})
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let This=this;
const query=wx.createSelectorQuery();
query.select('#tab').boundingClientRect(function(res)
{
This.data.tabTop=res.top//255
}
).exec();
},以上就是本文的全部内容,希望对大家的学习有所帮助。
食疗方法
动作方法
食疗方法
动作方法
/* 吸顶开始 */
.xiding
{
width: 100%;
height: 30px;
background: white;
}
.title-1
{
text-align: center;
}
.title-2
{
text-align: center;
}
/* 吸顶 */
.Fixed
{
position: fixed;
top: 0;
z-index: 2;
}
/* 吸顶结束 */
/* 吸顶开始 */
.xiding
{
width: 100%;
height: 30px;
background: white;
}
.title-1
{
text-align: center;
}
.title-2
{
text-align: center;
}
/* 吸顶 */
.Fixed
{
position: fixed;
top: 0;
z-index: 2;
}
/* 吸顶结束 */wxjs代码:
oneFixed:"",
tabTop:"0",
// 吸顶动态监听函数
onPageScroll:function(event)
{
console.log(event.scrollTop > this.data.tabTop)
if(event.scrollTop>this.data.tabTop)
{
if(this.data.tabFix)
{
return
}
else{
this.setData({
oneFixed:"Fixed"//添加吸顶类
})
}
}
else
{
this.setData({
oneFixed:''
})
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let This=this;
const query=wx.createSelectorQuery();
query.select('#tab').boundingClientRect(function(res)
{
This.data.tabTop=res.top//255
}
).exec();
},
oneFixed:"",
tabTop:"0",
// 吸顶动态监听函数
onPageScroll:function(event)
{
console.log(event.scrollTop > this.data.tabTop)
if(event.scrollTop>this.data.tabTop)
{
if(this.data.tabFix)
{
return
}
else{
this.setData({
oneFixed:"Fixed"//添加吸顶类
})
}
}
else
{
this.setData({
oneFixed:''
})
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let This=this;
const query=wx.createSelectorQuery();
query.select('#tab').boundingClientRect(function(res)
{
This.data.tabTop=res.top//255
}
).exec();
},以上就是本文的全部内容,希望对大家的学习有所帮助。