gui-scrollitems-y.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <scroll-view
  3. :scroll-y="!animating"
  4. :scroll-top="sctop"
  5. @scroll="scrolling"
  6. :scroll-with-animation="true"
  7. :show-scrollbar="false"
  8. :style="{height:height}">
  9. <view
  10. class="gui-scrollitemsy gui-flex gui-row gui-nowrap gui-space-between"
  11. hover-class="gui-tap"
  12. v-for="(item, idx) in itemsIn" :key="idx"
  13. :class="[ animating && idx == 0 ? 'gui-scrollitemsy-animate' : '']"
  14. :style="{opacity:animating && idx == 0 ? 0 : 1}"
  15. @touchstart="touchstart" @touchend="touchend"
  16. @tap="itemTap(idx)"
  17. ref="scitems">
  18. <image
  19. :src="item.img"
  20. mode="aspectFill"
  21. :style="imgStyle"></image>
  22. <view
  23. class="gui-scrollitemsy-body gui-flex1">
  24. <text
  25. class="gui-block"
  26. :style="textStyle">{{item.desc}}</text>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </template>
  31. <script>
  32. // #ifdef APP-NVUE
  33. const animation = weex.requireModule('animation');
  34. // #endif
  35. export default{
  36. name : "gui-scrollitems-y",
  37. props : {
  38. height : {type : String, default : '480rpx'},
  39. imgStyle : {type : String, default : 'width:88rpx; height:88rpx; border-radius:6rpx; margin-top:5rpx; margin-right:28rpx;'},
  40. textStyle : {type : String, default : 'font-size:28rpx; line-height:38rpx;'},
  41. items : {type : Array, default : function(){return [];}},
  42. duration : {type : Number, default : 6000}
  43. },
  44. data() {
  45. return {
  46. timer : null,
  47. timer2 : null,
  48. timer3 : null,
  49. animating : false,
  50. itemsIn : [],
  51. sctop : 0
  52. }
  53. },
  54. created:function(){
  55. this.itemsIn = this.items;
  56. this.timer = setTimeout(() => {this.animate();}, this.duration);
  57. },
  58. methods:{
  59. animate : function(){
  60. this.sctop = 0;
  61. var tmp = this.itemsIn.pop();
  62. this.items.unshift(tmp);
  63. this.animating = true;
  64. // #ifdef APP-NVUE
  65. setTimeout(() => {this.animateforweex();}, 200);
  66. // #endif
  67. setTimeout(()=>{ this.animating = false; }, 600);
  68. this.timer = setTimeout(() => {
  69. this.animate();
  70. }, this.duration);
  71. },
  72. touchstart : function(){
  73. clearTimeout(this.timer);
  74. },
  75. touchend : function(){
  76. clearTimeout(this.timer2);
  77. this.timer2 = setTimeout(()=>{
  78. this.sctop = 0;
  79. setTimeout(()=>{this.animate();}, 1000)
  80. }, 3000);
  81. },
  82. scrolling : function (e) {
  83. clearTimeout(this.timer3);
  84. this.timer3 = setTimeout(()=>{
  85. this.sctop = e.detail.scrollTop;
  86. },200);
  87. },
  88. itemTap : function(idx){
  89. this.$emit('itemTap', this.itemsIn[idx]);
  90. },
  91. addItem : function(obj){
  92. clearTimeout(this.timer);
  93. clearTimeout(this.timer2);
  94. this.itemsIn.push(obj);
  95. setTimeout(()=>{ this.sctop = 0; }, 500);
  96. setTimeout(()=>{ this.animate(); }, 1000);
  97. },
  98. animateforweex : function () {
  99. var ref = this.$refs.scitems[0];
  100. animation.transition(ref, {
  101. styles: {opacity:1},
  102. duration: 300, //ms
  103. timingFunction: 'ease',
  104. delay: 0 //ms
  105. });
  106. }
  107. },
  108. emits : ['itemTap']
  109. }
  110. </script>
  111. <style scoped>
  112. .gui-scrollitemsy{margin-bottom:30rpx;}
  113. .gui-scrollitemsy-body{overflow:hidden;}
  114. /* #ifndef APP-NVUE */
  115. @keyframes gui-scrollitemsy-animate{0%{height:0;} 100%{height:100rpx;}}
  116. .gui-scrollitemsy-animate{animation:gui-scrollitemsy-animate 500ms ease-in; }
  117. /* #endif */
  118. </style>