微信小程序 scroll-view禁止滚动

我用的很简单的方法 在scroll-y=“{{gun}}” 然后需要的地方设置true或false 最后判断

感谢他们给我的启发
作者:qwy0419
//来源:CSDN
//原文:https://blog.csdn.net/qwy0419/article/details/80357232
//版权声明:本文为博主原创文章,转载请附上博文链接!

//---------------------
//作者:张育嘉
//来源:CSDN
//原文:https://blog.csdn.net/code_shadow/article/details/80372516
//版权声明:本文为博主原创文章,转载请附上博文链接!

先设置触底事件 bindscrolltolower="l" 当滚动到底部时触发 l


下面是 l
通过将scroll-y="{{gun}}"的gun设置为false停止页面滚动

l:function(){
    
   this.setData({ xianshi: false })//让底部显示等待
     console.log(this.data.xianshi)
     this.data.shifoukaiqi=true;//设置是否开启l6
    this.l6()//开启l6
    this.setData({top:false})//显示返回顶部按钮
    this.setData({gun:false})//将
    this.setData({jinzhidianji:false})//bu rang dian ji fanhui
    },

下面是l6

l6: function () {
    if(this.data.shifoukaiqi==true){//如果shifoukaiqi为true
      this.setData({ jici: this.data.jici = this.data.jici + 10 })//设置请求内容数量
    var that=this;
    console.log("kaiqi")
   setTimeout(function(){
     that.setData({xianshi:true})//rang jia zai yin cang
     that.l66()//开启计时后   执行l66
     

   },6000)
    }
  },

下面是l66

l66: function () {
    console.log("开启");

    this.ajax()//执行ajax请求数据
    this.setData({ xianshi: true })//让显示等待窗口隐藏
    this.data.shifoukaiqi = false;// 将shifoukaiqi设置为false  关闭l6  这里是为了让l6仅运行一次
    this.setData({gun:true})//让滚动条变为能滚动
    this.setData({jinzhidianji:true})//yun xu dian ji fanhui
 
  },

下面是xml中显示等待view


需要留心的是 需要将z-index设置为1 显示在scrollview上方

   .u{margin-top:-30px;position:absolute;z-index: 1;background-color: rgb(175, 215, 252);text-align: center}

下面是全部代码








用户名:{{item.username}}
密码:{{item.password}}
{{item.latitude}}
{{item.longitude}}
{{item.nr}}
{{item.data}}
{{item.id}}



  

js

//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    nr6: '',
    lc:'\n',
    latitude:'',
    longitude:'',
    jici:10,
    xianshi:true,
    shifoukaiqi:false,
    top:true,
    gun:true,
    jinzhidianji:true
   // var cont = result.concat(resArr);
  },






  //事件处理函数







  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
    ///
    //获取窗口高度
  
  },
 // onShow:function(){
    //console.log(id);
   // var self = this
   // wx.getLocation({
   //   type: 'wgs84',

   //   success: function (res) {
        // console.log(res);
     //   var latitude = res.latitude;
     //   getApp().globalData.latitude = res.latitude;
     //   var longitude = res.longitude;
     //   self.setData({
     //     latitude: res.latitude,
     //     longitude: res.longitude//buyong在上面的data中初始化变量,在这set
      //  })
        //console.log(latitude);
        //弹框

     // }
  //  })
  //},
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  gotoresult:

    function (e) {

      var kind = e.target.id
      console.log(kind);

    },
  d:
    function (e) {
      var cc = e.target.id
      ///console.log(c);
      //console.log(e.target.setData)
      // var c=6;

    },
  //onLoad: function () {
   // console.log("cc6");
   // var ccc = d();
  //},
  //onLoad: function (e) {
    //var self = this
   // wx.getLocation({
   //   type: 'wgs84',

    //  success: function (res) {
        // console.log(res);
       // var latitude = res.latitude;
       // getApp().globalData.latitude = res.latitude;
      //  var longitude = res.longitude;
     //   self.setData({
      //    latitude: latitude,
      //    longitude: longitude//buyong在上面的data中初始化变量,在这set
     //   })
        //console.log(latitude);
        //弹框

  //    }
   // })
 // },
  //---------------------
  // 



  bindtest: function () {
    var that = this;
    wx.request({
      url: 'http://localhost:9090/xiaochengxu/servlet/nr',
      data: {
        username: '张育嘉',
        password: '123',
        //var latitude=app.globalData.latitude;/:this.g

        latitude: app.globalData.latitude,//从全局变量app.js中取
        longitude: this.data.longitude,//从data中取
        nr: this.data.nr
      },
      method: 'POST',
      header: {
        //'content-type': 'application/json' // 默认值
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data);
        //that.setData({nr6:res.data.username,});
      },
      fail: function (res) {
        console.log(".....6666.....");
      }
    })
  }
 
  ,
  lalala: function (e) {
    var nr = e.detail.value;
    this.setData({
      nr: nr,
    })

  },
  //on: function () {
    //var id = options.Id;
    //console.log(id);
  //
  //console.log(this.data.longitude);
  //},

  //
  ///
  //调用wei 因为onload不能重复调用
  onLoad: function () {//http://www.imooc.com/wenda/detail/486087 异步调用
    var self = this

    // var self = this;
    wx.getSystemInfo({
      success: function (res) {
        let scrollH = res.windowHeight;
        console.log(scrollH);
        self.setData({
          scrollL: scrollH
        });
      }
    });
    // this.on();
    var that = this//https://bbs.csdn.net/topics/392209355?list=lz
    var wei=this.lc(function(wei){
      console.log(wei);

    wx.request({
      url: 'https://www.fuhufuhu.com/xcxmvc/nr/dl',

      method: 'get',
      data: {
        latitude: wei.latitude,
        //longitude:longitude,
        //longitude: wei.longitude
        longitude:wei.longitude,
        jici:that.data.jici
      },
      header: {
        'content-type': 'application/json' // 默认值
        // 'Content-Type': 'application/x-www-form-urlencoded'
      },

      success: function (res) {

        that.setData({ nr6: res.data });
       // console.log(res.data.lo);
        //测试
        
        
        //var json=JSON.parse(res.data);
        //console.log(res.data[0].id);
      },
      fail: function (res) {
        console.log(".....fail.....");
      }
      })
    
    });
   
   // this.bind();
    
  },
io:function(){this.setData({shifoukaiqi:false})},
  l6: function () {
    if(this.data.shifoukaiqi==true){//ru guo kai qi
      this.setData({ jici: this.data.jici = this.data.jici + 10 })
    var that=this;
    console.log("kaiqi")
   setTimeout(function(){
     that.setData({xianshi:true})//rang jia zai yin cang
     that.l66()//zhi xing l66
     
   // that.io()
    // that.l()
   },6000)
    }
  },
 returntop:function(){
   if(this.data.jinzhidianji==true){//ru guo yun xu dian ji
   this.setData({fanhui:0})//scroll-top gui 0
   console.log("return")
   this.setData({top:true})//yin cang dian ji view
   }
 },
  //onReachBottom() {
   // this.setData({ jici: this.data.jici = this.data.jici + 10 })
    //console.log(this.data.jici);
  
   // this.ajax()},
  l66: function () {
    console.log("开启");
    //this.setData({ jici: this.data.jici = this.data.jici + 10 })
    //console.log(this.data.jici);
    this.ajax()//zhi xing ajax
    this.setData({ xianshi: true })//xia la xian shi yin cang
    this.data.shifoukaiqi = false;// guan bi l6
    this.setData({gun:true})//kai qi gun dong
    this.setData({jinzhidianji:true})//yun xu dian ji fanhui
 
  },
  l:function(){
    //this.setData({ jici: this.data.jici = this.data.jici + 10})
   this.setData({ xianshi: false })//xia la xian shi yin cang
     console.log(this.data.xianshi)
     this.data.shifoukaiqi=true;//rang l6 gongzuo  jinyici
    this.l6()
    this.setData({top:false})//rang fan hui view xian shi
    this.setData({gun:false})//bu rang gun dong
    this.setData({jinzhidianji:false})//bu rang dian ji fanhui
    },
 
  /
  //
  //用wei保存位置信息
  lc: function (wei) {
    var self = this
    wx.getLocation({
      type: 'wgs84',

      success: function (res) {
        
       wei(res);
       return wei;
      }
    })
   
  // this.ajax();//调用ajax函数
  },

  kantie:function(e){
   // wx.redirectTo({
   //   url: '../../kantie/kantie',
   // })
    
    var ccc=e.currentTarget.dataset.id;//获取view中的药用currentTarget
    console.log(ccc);
    wx.navigateTo({
      url: '../../kantie/kantie?Id='+ccc,
    })
  },
 
  ajax:function(){
   // this.setData({ s6: 0 });
    var that = this//https://bbs.csdn.net/topics/392209355?list=lz
    
    console.log(this.data.jici);
    var ji=this.data.jici;
    var wei = this.lc(function (wei) {
     

      wx.request({
        url: 'https://www.fuhufuhu.com/xcxmvc/nr/dl',

        method: 'get',
        data: {
          latitude: wei.latitude,
          //longitude:longitude,
          //longitude: wei.longitude
          longitude: wei.longitude,
          jici:ji,
        },
        header: {
          'content-type': 'application/json' // 默认值
          // 'Content-Type': 'application/x-www-form-urlencoded'
        },

        success: function (res) {

          that.setData({ nr6: res.data });
          // console.log(res.data.lo);
          //测试


          //var json=JSON.parse(res.data);
          //console.log(res.data[0].id);
        },
        fail: function (res) {
          console.log(".....fail.....");
        }
      })

    });
  },
})

微信小程序 scroll-view禁止滚动_第1张图片

你可能感兴趣的:(日记)