Authored by Aiden Xu

商品详情

@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 7
8 'use strict'; 8 'use strict';
9 9
  10 +const $ = require('yoho-jquery');
10 const template = require('components/modal.hbs'); 11 const template = require('components/modal.hbs');
11 const Overlay = require('./overlay'); 12 const Overlay = require('./overlay');
12 13
@@ -7,6 +7,8 @@ @@ -7,6 +7,8 @@
7 7
8 'use strict'; 8 'use strict';
9 9
  10 +const $ = require('yoho-jquery');
  11 +
10 const ANIMATIONS = { 12 const ANIMATIONS = {
11 none: { 13 none: {
12 in: 'overlay-in', 14 in: 'overlay-in',
@@ -66,6 +68,18 @@ class Overlay { @@ -66,6 +68,18 @@ class Overlay {
66 .removeClass(this.settings.animationClasses.out); 68 .removeClass(this.settings.animationClasses.out);
67 } 69 }
68 70
  71 + _cleanupListener() {
  72 + this.elem.css({
  73 + visibility: 'hidden'
  74 + });
  75 + this._clearStylesClasses();
  76 + this.isVisible = false;
  77 + this.elem.detach();
  78 +
  79 + // 一次性监听,动画完成事件触发后删除监听器
  80 + this.elem[0].removeEventListener('webkitTransitionEnd', this._cleanupListener);
  81 + }
  82 +
69 /** 83 /**
70 * 显示覆盖层 84 * 显示覆盖层
71 */ 85 */
@@ -95,19 +109,8 @@ class Overlay { @@ -95,19 +109,8 @@ class Overlay {
95 hide() { 109 hide() {
96 if (this.isVisible) { 110 if (this.isVisible) {
97 this._clearStylesClasses(); 111 this._clearStylesClasses();
98 - const listener = () => {  
99 - this.elem.css({  
100 - visibility: 'hidden'  
101 - });  
102 - this._clearStylesClasses();  
103 - this.isVisible = false;  
104 - this.elem.detach();  
105 112
106 - // 一次性监听,动画完成事件触发后删除监听器  
107 - this.elem[0].removeEventListener('webkitTransitionEnd', listener);  
108 - };  
109 -  
110 - this.elem[0].addEventListener('webkitTransitionEnd', listener); 113 + this.elem[0].addEventListener('webkitTransitionEnd', this._cleanupListener.bind(this));
111 this.elem.addClass(this.settings.animationClasses.out); 114 this.elem.addClass(this.settings.animationClasses.out);
112 115
113 if (this.settings.disableScrolling) { 116 if (this.settings.disableScrolling) {
@@ -116,6 +119,10 @@ class Overlay { @@ -116,6 +119,10 @@ class Overlay {
116 }); 119 });
117 } 120 }
118 121
  122 + setTimeout(()=> {
  123 + this._cleanupListener();
  124 + }, 100);
  125 +
119 this.settings.onClose(); 126 this.settings.onClose();
120 } 127 }
121 } 128 }
1 const Vue = require('yoho-vue'); 1 const Vue = require('yoho-vue');
2 const app = require('product/detail/index.vue'); 2 const app = require('product/detail/index.vue');
3 const loading = require('common/loading'); 3 const loading = require('common/loading');
4 -const _ = require('lodash'); 4 +const lazyload = require('yoho-vue-lazyload');
5 5
6 require('../common/overlay'); 6 require('../common/overlay');
7 7
  8 +Vue.use(lazyload);
  9 +
  10 +(() => {
  11 + let stop = 0;
  12 +
  13 + $(document).ajaxStart(()=> {
  14 + // start = new Date().getTime();
  15 +
  16 + // setTimeout(()=> {
  17 + if (stop === 0) { // 超过100ms请求仍未结束则显示
  18 + loading.show();
  19 + }
  20 +
  21 + // }, 100);
  22 + });
  23 +
  24 + $(document).ajaxStop(()=> {
  25 + stop = new Date().getTime();
  26 + loading.hide();
  27 + });
  28 +})();
  29 +
8 new Vue({ 30 new Vue({
9 el: '#app', 31 el: '#app',
10 components: { 32 components: {
@@ -12,14 +34,4 @@ new Vue({ @@ -12,14 +34,4 @@ new Vue({
12 } 34 }
13 }); 35 });
14 36
15 -$(document).ajaxStart(()=> {  
16 - _.debounce(()=> {  
17 - loading.show();  
18 - }, 100)();  
19 -});  
20 37
21 -$(document).ajaxStop(()=> {  
22 - _.debounce(()=> {  
23 - loading.hide();  
24 - }, 500)();  
25 -});