add wraper only when there is enough elements to wrap. code review by LZF
Showing
1 changed file
with
6 additions
and
2 deletions
@@ -50,9 +50,13 @@ function hiddenTips($ele) { | @@ -50,9 +50,13 @@ function hiddenTips($ele) { | ||
50 | //} | 50 | //} |
51 | 51 | ||
52 | function wrapElements(selector, count) { | 52 | function wrapElements(selector, count) { |
53 | + var elArr = null; | ||
54 | + | ||
53 | $(selector).each(function(idx, el) { | 55 | $(selector).each(function(idx, el) { |
54 | - if (idx % count === 0) { | ||
55 | - $($(selector).slice(idx, idx + count)).wrapAll($('<div class="js-wraper"></div>')); | 56 | + elArr = $(selector).slice(idx, idx + count); |
57 | + | ||
58 | + if (elArr.length === count && idx % count === 0) { | ||
59 | + $(elArr).wrapAll($('<div class="js-wraper"></div>')); | ||
56 | } | 60 | } |
57 | }); | 61 | }); |
58 | } | 62 | } |
-
Please register or login to post a comment