gui-scrollitems-y.vue 3.1 KB

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