index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Component({
  2. externalClasses: ['i-class'],
  3. properties : {
  4. scrollTop : {
  5. type : Number,
  6. observer(val){
  7. this._updateScrollTopChange();
  8. }
  9. }
  10. },
  11. relations : {
  12. '../sticky-item/index' : {
  13. type : 'child',
  14. linked(){
  15. this._updateDataChange();
  16. },
  17. linkChanged () {
  18. this._updateDataChange();
  19. },
  20. unlinked () {
  21. this._updateDataChange();
  22. }
  23. }
  24. },
  25. data : {
  26. timer : null,
  27. itemLength : 0,
  28. },
  29. methods : {
  30. _updateScrollTopChange(){
  31. const stickies = this.getRelationNodes('../sticky-item/index');
  32. if( stickies.length > 0 ){
  33. stickies.forEach((item) => {
  34. if( item ){
  35. item.updateScrollTopChange( this.data.scrollTop );
  36. }
  37. })
  38. }
  39. },
  40. _updateDataChange( ){
  41. const stickies = this.getRelationNodes('../sticky-item/index');
  42. if( stickies.length > 0 ){
  43. if( this.data.timer ){
  44. clearTimeout( this.data.timer )
  45. this.setData({
  46. timer : null
  47. })
  48. }
  49. this.data.timer = setTimeout(()=>{
  50. stickies.forEach((item,index) => {
  51. if( item ){
  52. item.updateDataChange(index);
  53. }
  54. })
  55. },0)
  56. this.setData({
  57. timer : this.data.timer
  58. })
  59. }
  60. }
  61. }
  62. })