为评论和咨询切换绑定tap事件 --code reviewed by zhaobiao
Showing
1 changed file
with
15 additions
and
9 deletions
@@ -10,7 +10,10 @@ var $ = require('jquery'), | @@ -10,7 +10,10 @@ var $ = require('jquery'), | ||
10 | var commentsNum,consultsNum; | 10 | var commentsNum,consultsNum; |
11 | 11 | ||
12 | var consultFooterEle = document.getElementById('consult-content-footer'), | 12 | var consultFooterEle = document.getElementById('consult-content-footer'), |
13 | - consultFooterHammer = consultFooterEle && new Hammer(consultFooterEle); | 13 | + consultFooterHammer = consultFooterEle && new Hammer(consultFooterEle), |
14 | + | ||
15 | + navtabEle = document.getElementById('nav-tab'), | ||
16 | + navtabHammer = navtabEle && new Hammer(navtabEle); | ||
14 | 17 | ||
15 | 18 | ||
16 | (function() { | 19 | (function() { |
@@ -36,26 +39,29 @@ var consultFooterEle = document.getElementById('consult-content-footer'), | @@ -36,26 +39,29 @@ var consultFooterEle = document.getElementById('consult-content-footer'), | ||
36 | 39 | ||
37 | })(); | 40 | })(); |
38 | 41 | ||
39 | -$('#nav-tab li').on('touchend', function() { | ||
40 | - var index = $(this).index(); | 42 | +if (navtabHammer) { |
43 | + navtabHammer.on('tap', function(e) { | ||
44 | + var $this = $(e.target).closest('li'); | ||
45 | + var index = $this.index(); | ||
41 | 46 | ||
42 | - if ($(this).hasClass('comment-nav') && 0 === commentsNum) { | 47 | + if ($this.hasClass('comment-nav') && 0 === commentsNum) { |
43 | tip.show('暂无商品评价'); | 48 | tip.show('暂无商品评价'); |
44 | } else { | 49 | } else { |
45 | - if (!$(this).hasClass('focus')) { | 50 | + if (!$this.hasClass('focus')) { |
46 | 51 | ||
47 | $('#nav-tab li').each(function() { | 52 | $('#nav-tab li').each(function() { |
48 | - $(this).removeClass('focus'); | 53 | + $this.removeClass('focus'); |
49 | }); | 54 | }); |
50 | $('#feedback-content .content').each(function() { | 55 | $('#feedback-content .content').each(function() { |
51 | - $(this).addClass('hide'); | 56 | + $this.addClass('hide'); |
52 | }); | 57 | }); |
53 | 58 | ||
54 | - $(this).addClass('focus'); | 59 | + $this.addClass('focus'); |
55 | $('#feedback-content .content:eq(' + index + ')').removeClass('hide'); | 60 | $('#feedback-content .content:eq(' + index + ')').removeClass('hide'); |
56 | } | 61 | } |
57 | } | 62 | } |
58 | -}); | 63 | + }); |
64 | +} | ||
59 | 65 | ||
60 | if (consultFooterHammer) { | 66 | if (consultFooterHammer) { |
61 | consultFooterHammer.on('tap', function() { | 67 | consultFooterHammer.on('tap', function() { |
-
Please register or login to post a comment