Authored by 沈志敏

select 框优化

1 <div class="select"> 1 <div class="select">
2 <ul> 2 <ul>
3 {{#each items}} 3 {{#each items}}
4 - <li class="item-li" key="{{key}}">{{val}}</li> 4 + <li class="item-li {{#if disabled}} disabled {{/if}}" key="{{key}}" status="{{disabled}}">{{val}}</li>
5 {{/each}} 5 {{/each}}
6 <li class="item-del"> 6 <li class="item-del">
7 <span>取消</span> 7 <span>取消</span>
@@ -28,40 +28,49 @@ function Select(items) { @@ -28,40 +28,49 @@ function Select(items) {
28 // 覆盖层 28 // 覆盖层
29 const overlay = new Overlay({ 29 const overlay = new Overlay({
30 onClose: function() { 30 onClose: function() {
  31 + elem.removeClass('slide-in');
31 elem.hide(); 32 elem.hide();
32 } 33 }
33 }); 34 });
34 35
35 - $(del).click(function() { 36 + const hide = function() {
  37 + elem.removeClass('slide-in');
36 overlay.hide(); 38 overlay.hide();
37 elem.hide(); 39 elem.hide();
38 - }); 40 + }
39 41
40 - return {  
41 - show: function(cb) {  
42 - if (elem.parent().length === 0) {  
43 - const lis = elem.find('.item-li'); 42 + const show = function(cb) {
  43 + if (elem.parent().length === 0) {
  44 + const lis = elem.find('.item-li');
44 45
45 - lis.each(function() { 46 + lis.each(function() {
  47 + if (!$(this).attr('status')) {
46 $(this).click(function(e) { 48 $(this).click(function(e) {
47 - overlay.hide();  
48 - elem.hide(); 49 + hide();
49 cb({ 50 cb({
50 key: $(e.target).attr('key'), 51 key: $(e.target).attr('key'),
51 val: e.target.innerHTML 52 val: e.target.innerHTML
52 }); 53 });
53 }); 54 });
54 - });  
55 - elem.appendTo('body').addClass('animation-target');  
56 - }  
57 -  
58 - overlay.show();  
59 - elem.show();  
60 - },  
61 - hide: function() {  
62 - overlay.hide();  
63 - elem.hide(); 55 + }
  56 + });
  57 + elem.appendTo('body');
64 } 58 }
  59 +
  60 + overlay.show();
  61 + elem.show();
  62 + setTimeout(() => {
  63 + elem.addClass('slide-in');
  64 + }, 200);
  65 + }
  66 +
  67 + $(del).click(function() {
  68 + hide();
  69 + });
  70 +
  71 + return {
  72 + show: show,
  73 + hide: hide
65 }; 74 };
66 } 75 }
67 76
@@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
4 width: 100%; 4 width: 100%;
5 background: #fff; 5 background: #fff;
6 z-index: 1001; 6 z-index: 1001;
  7 + transform: translate3d(0, 100%, 0);
  8 + transition: all 0.1s ease-in-out;
7 9
8 ul { 10 ul {
9 font-size: 34px; 11 font-size: 34px;
@@ -15,10 +17,18 @@ @@ -15,10 +17,18 @@
15 border-bottom: 1px solid #e0e0e0; 17 border-bottom: 1px solid #e0e0e0;
16 } 18 }
17 19
  20 + .disabled {
  21 + color: #b0b0b0;
  22 + }
  23 +
18 .item-del { 24 .item-del {
19 margin-top: 10px; 25 margin-top: 10px;
20 border-top: 1px solid #e0e0e0; 26 border-top: 1px solid #e0e0e0;
21 color: #5c99e4; 27 color: #5c99e4;
22 } 28 }
23 } 29 }
  30 +
  31 + &.slide-in {
  32 + transform: translate3d(0, 0, 0);
  33 + }
24 } 34 }
@@ -62,7 +62,6 @@ @@ -62,7 +62,6 @@
62 let _this = this; 62 let _this = this;
63 63
64 genderSel.show(function(item) { 64 genderSel.show(function(item) {
65 - console.log(item)  
66 _this.gender = item.val.toLowerCase(); 65 _this.gender = item.val.toLowerCase();
67 _this.saveDetails({ 66 _this.saveDetails({
68 nickname: _this.nickname, 67 nickname: _this.nickname,