经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » 微信小程序 » 查看文章
微信小程序页面上下滚动效果
来源:jb51  时间:2019/7/16 8:35:10  对本文有异议

本文实例为大家分享了微信小程序页面上下滚动的具体代码,供大家参考,具体内容如下

看图

源码

  1. <view class="container container-fill">
  2. <view class="scroll-fullpage" bindtouchstart="scrollTouchstart" bindtouchmove="scrollTouchmove" bindtouchend="scrollTouchend" style="transform:translateY(-{{scrollindex*100}}%);margin-top: {{margintop}}px">
  3. <view class="section section01 {{scrollindex==0?'active':''}}" style="background: #3399FF;">
  4. <text class="section-maintitle">页面1</text>
  5. <text class="section-subtitle">我的页面”1</text>
  6. </view>
  7. <view class="section section02 {{scrollindex==1?'active':''}}" style="background: #00CC66;">
  8. <text class="section-maintitle">页面2</text>
  9. <text class="section-subtitle">我的页面”2</text>
  10. </view>
  11. <view class="section section03 {{scrollindex==2?'active':''}}" style="background: #33CCCC;">
  12. <text class="section-maintitle">页面3</text>
  13. <text class="section-subtitle">我的页面”3</text>
  14. </view>
  15. <view class="section section04 {{scrollindex==3?'active':''}}" style="background: #6699FF;">
  16. <text class="section-maintitle">页面4</text>
  17. <text class="section-subtitle">我的页面”4</text>
  18. </view>
  19. <view class="section section05 {{scrollindex==4?'active':''}}" style="background: #9966FF;">
  20. <text class="section-maintitle">无缝对接双创服5</text>
  21. <text class="section-subtitle">我的页面”5</text>
  22. </view>
  23. </view>
  24. </view>

js

  1. Page({
  2. data: {
  3. scrollindex:0, //当前页面的索引值
  4. totalnum:5, //总共页面数
  5. starty:0, //开始的位置x
  6. endy:0, //结束的位置y
  7. critical: 100, //触发翻页的临界值
  8. margintop:0, //滑动下拉距离
  9. },
  10. onLoad: function () {
  11. },
  12. scrollTouchstart:function(e){
  13. let py = e.touches[0].pageY;
  14. this.setData({
  15. starty: py
  16. })
  17. },
  18. scrollTouchmove:function(e){
  19. let py = e.touches[0].pageY;
  20. let d = this.data;
  21. this.setData({
  22. endy: py,
  23. })
  24. if(py-d.starty<100 && py-d.starty>-100){
  25. this.setData({
  26. margintop: py - d.starty
  27. })
  28. }
  29. },
  30. scrollTouchend:function(e){
  31. let d = this.data;
  32. if(d.endy-d.starty >100 && d.scrollindex>0){
  33. this.setData({
  34. scrollindex: d.scrollindex-1
  35. })
  36. }else if(d.endy-d.starty <-100 && d.scrollindex<this.data.totalnum-1){
  37. this.setData({
  38. scrollindex: d.scrollindex+1
  39. })
  40. }
  41. this.setData({
  42. starty:0,
  43. endy:0,
  44. margintop:0
  45. })
  46. },
  47. })

css

  1. .container-fill{
  2. height: 100%;
  3. overflow: hidden;
  4. }
  5. .scroll-fullpage{
  6. height: 100%;
  7. transition: all 0.3s;
  8. }
  9. .section{
  10. height: 100%;
  11. }
  12. .section-maintitle{
  13. display: block;
  14. text-align: center;
  15. font-size: 50rpx;
  16. color: #fff;
  17. font-weight: bold;
  18. letter-spacing: 10rpx;
  19. padding-top: 140rpx;
  20. }
  21. .section-subtitle{
  22. display: block;
  23. text-align: center;
  24. font-size: 40rpx;
  25. color: #fff;
  26. font-weight: bold;
  27. letter-spacing: 10rpx;
  28. }
  29. .active .section-maintitle,
  30. .active .section-subtitle{
  31. animation: mymove 0.8s;
  32. }
  33. @keyframes mymove{
  34. from {
  35. transform: translateY(-400rpx) scale(0.5) rotateY(90deg);
  36. }
  37. to {
  38. transform: translateY(0) scale(1) rotateY(0);
  39. }
  40. }

 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号