1、原理:利用小程序自带的<scroll-view>组件,该组件的bindScroll和scroll-top方法、属性进行联合操作

2、效果图:

3、wxml:

<scroll-view  scroll-y="true" style="height:{{scrollHeight}}px;" bindscroll="scroll" scroll-top="{{scrollTop}}" >
<text class="title">{{list.art_title}}</text>
<p class="oneline">{{list.seo_desc}}</p> <!--回到顶部 -->
<view class="com-widget-goTop" bindtap="goTop" wx:if="{{floorstatus}}">
<view class="icon-gotop">
顶部
</view>
</view> </scroll-view>

4、js:

  scroll: function (e, res) {
// 容器滚动时实时获取滚动高度:e.detail.scrollTop
//当超过限定值如500时,展示【返回顶部图片】,通过标识"floorstatus"的真假判断展示、隐藏
if (e.detail.scrollTop > 500) {
this.setData({
floorstatus: true
});
}
else {
this.setData({
floorstatus: false
});
}
},
// 点击图片,使scrollTop属性==0,回到顶部
goTop: function (e) {
this.setData({
scrollTop: 0
})
},

5、wxss:

/*回到顶部  */
.com-widget-goTop {
position: fixed;
bottom: 125px;
right: 5px;
background: rgba(0,0,0,0.48);
border-radius: 50%;
overflow: hidden;
z-index:;
}
.com-widget-goTop .icon-gotop{
background-color: rgba(0,0,0,0.8);
display: inline-block;
width: 50px;
height: 50px;
line-height: 68px;
font-size: 12px;
color: #ffffff;
text-align: center;
border-radius: 50%;
background:url(http://m.dev.vd.cn/static/xcx/v1/goo/w_2-3451cc437e.png) no-repeat center -1110px;
background-size:50px auto;
}
/*end*/

最新文章

  1. Bootstrap-Select 动态加载数据的小记
  2. 在php中定义常量时,const与define的区别?
  3. 理解C# 4 dynamic(2) – ExpandoObject的使用
  4. 浅谈c语言的指针
  5. jvm基础笔记
  6. 二叉树的遍历(递归,迭代,Morris遍历)
  7. PostgreSQL Replication之第十二章 与Postgres-XC一起工作(1)
  8. spoj 274
  9. 英文论文写作之讨论与结论Discussion and Conclusion
  10. IEnumerable中的 Any方法
  11. android在桌面弹出一个窗口
  12. lucene 总结收集(url)
  13. Chrome浏览器扩展开发系列之十二:Content Scripts
  14. DispatcherTimer和Timer(计时器)
  15. Android 程序结构
  16. Python filter() 函数
  17. Integer 函数传参实现值交换
  18. 模块化jQuery的方法
  19. Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment:
  20. 人人中的 shiro权限管理 简单说明

热门文章

  1. CASpringAnimation的使用
  2. 仿LOL项目开发第九天
  3. 计算均值mean的MapReduce程序Computing mean with MapReduce
  4. 第二章 JVM内存分配
  5. How To Open An URL In Android’s Web Browser
  6. Android中Dialog对话框的调用及监听
  7. WebSettings 文档 API 翻译 常用设置
  8. 集合 数组 定义 转换 遍历 Arrays API MD
  9. Android -- ImageLoader本地缓存
  10. [Algorithm] Radix Sort Algorithm