index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Component({
  2. externalClasses: ['i-class'],
  3. options: {
  4. multipleSlots: true
  5. },
  6. relations : {
  7. '../sticky/index' : {
  8. type : 'parent'
  9. }
  10. },
  11. data : {
  12. top : 0,
  13. height : 0,
  14. isFixed : false,
  15. index : -1,
  16. },
  17. methods: {
  18. updateScrollTopChange(scrollTop){
  19. const data = this.data;
  20. const top = data.top;
  21. const height = data.height;
  22. this.setData({
  23. isFixed : ( scrollTop >= top && scrollTop < top + height ) ? true : false
  24. })
  25. },
  26. updateDataChange(index) {
  27. const className = '.i-sticky-item';
  28. const query = wx.createSelectorQuery().in(this);
  29. query.select( className ).boundingClientRect((res)=>{
  30. if( res ){
  31. this.setData({
  32. top : res.top,
  33. height : res.height,
  34. index : index
  35. })
  36. }
  37. }).exec()
  38. }
  39. }
  40. })