Authored by biao

修复购物车面板滑动问题。code review by LZF

@@ -77,13 +77,13 @@ function preventDefault(e) { @@ -77,13 +77,13 @@ function preventDefault(e) {
77 e.returnValue = false; 77 e.returnValue = false;
78 } 78 }
79 79
80 -function stopPropagation(e){ 80 +function stopPropagation(e) {
81 e = e || window.event; 81 e = e || window.event;
82 e.stopPropagation && e.stopPropagation(); 82 e.stopPropagation && e.stopPropagation();
83 e.cancelBubble = false; 83 e.cancelBubble = false;
84 } 84 }
85 85
86 -function innerScroll(e){ 86 +function innerScroll(e) {
87 var delta = e.wheelDelta || e.originalEvent.wheelDelta || e.detail || 0, 87 var delta = e.wheelDelta || e.originalEvent.wheelDelta || e.detail || 0,
88 box = $(this).get(0); 88 box = $(this).get(0);
89 89
@@ -92,20 +92,18 @@ function innerScroll(e){ @@ -92,20 +92,18 @@ function innerScroll(e){
92 stopPropagation(e); 92 stopPropagation(e);
93 93
94 94
95 - if($(box).height() + box.scrollTop >= box.scrollHeight){  
96 - if(delta < 0) { 95 + if ($(box).height() + box.scrollTop >= box.scrollHeight) {
  96 + if (delta < 0) {
97 preventDefault(e); 97 preventDefault(e);
98 return false; 98 return false;
99 } 99 }
100 } 100 }
101 - if(box.scrollTop === 0){  
102 - if(delta > 0) { 101 + if (box.scrollTop === 0) {
  102 + if (delta > 0) {
103 preventDefault(e); 103 preventDefault(e);
104 return false; 104 return false;
105 } 105 }
106 } 106 }
107 - // 会阻止原生滚动  
108 - // return false;  
109 } 107 }
110 108
111 function disableScroll() { 109 function disableScroll() {
@@ -124,10 +122,13 @@ function disableScroll() { @@ -124,10 +122,13 @@ function disableScroll() {
124 122
125 // 仿innerScroll方法 123 // 仿innerScroll方法
126 $choseArea.on('touchmove', function(e) { 124 $choseArea.on('touchmove', function(e) {
  125 + var deltaX = e.originalEvent.changedTouches[0].pageX - startX,
  126 + deltaY = e.originalEvent.changedTouches[0].pageY - startY;
  127 +
  128 + var box = $(this).get(0);
  129 +
127 e.stopPropagation(); 130 e.stopPropagation();
128 131
129 - var deltaX = e.originalEvent.changedTouches[0].pageX - startX;  
130 - var deltaY = e.originalEvent.changedTouches[0].pageY - startY;  
131 132
132 // 只能纵向滚 133 // 只能纵向滚
133 if (Math.abs(deltaY) < Math.abs(deltaX)) { 134 if (Math.abs(deltaY) < Math.abs(deltaX)) {
@@ -135,7 +136,6 @@ function disableScroll() { @@ -135,7 +136,6 @@ function disableScroll() {
135 return false; 136 return false;
136 } 137 }
137 138
138 - var box = $(this).get(0);  
139 139
140 if ($(box).height() + box.scrollTop >= box.scrollHeight) { 140 if ($(box).height() + box.scrollTop >= box.scrollHeight) {
141 if (deltaY < 0) { 141 if (deltaY < 0) {