你好!有以下构造:
popup-window带有类别列表的模态窗口(单击 时出现add-category);categories-list- 放置所选类别的块。
逻辑如下:一个人按下按钮Add Category,出现一个模态窗口 - 在这里选择必要的类别,按下它Choose并且标有所选类别的类别出现在块字段中categories-list。每个块类别categories-list都有一个“删除”按钮 - 即。通过单击它,类别消失并:checked在模态中被删除。
一个很大的要求来解释如何做到这一点,因为jQuery我有一个级别addClass/ removeClass。
$('.categories-list .add-category').click(function () {
if ($('#select-category-popup').css('display') == 'none') {
$('#select-category-popup').fadeIn();
}
});
$('.close-modal-window').click(function () {
$('#select-category-popup').fadeOut();
});
$('.choose-btn').click(function() {
$('#select-category-popup').fadeOut();
})
.categories-list {
padding: 10px 20px 0 20px;
border-bottom: none;
list-style: none;
font-size: 0;
line-height: 0;
border: 1px solid #333;
}
.categories-list .category {
display: inline-block;
margin: 0 10px 10px 0;
position: relative;
border: 1px solid transparent;
padding: 6px 32px 4px 10px;
font-size: 14px;
line-height: 14px;
border-radius: 4px;
cursor: pointer;
-moz-transition: all 0.4s cubic-bezier(0.2, 0.57, 0.36, 0.8);
-o-transition: all 0.4s cubic-bezier(0.2, 0.57, 0.36, 0.8);
-webkit-transition: all 0.4s cubic-bezier(0.2, 0.57, 0.36, 0.8);
transition: all 0.4s cubic-bezier(0.2, 0.57, 0.36, 0.8);
}
.categories-list .category.selected-category {
background: #eeeeee;
}
.categories-list .category .category-icon {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 32px;
}
.categories-list .category .category-icon:after {
content: '';
font-family: 'FontAwesome';
font-size: 16px;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
-moz-transition: all 0.4s cubic-bezier(0.2, 0.57, 0.36, 0.8);
-o-transition: all 0.4s cubic-bezier(0.2, 0.57, 0.36, 0.8);
-webkit-transition: all 0.4s cubic-bezier(0.2, 0.57, 0.36, 0.8);
transition: all 0.4s cubic-bezier(0.2, 0.57, 0.36, 0.8);
}
.categories-list .category .category-icon.delete:after {
content: '\f00d';
padding-bottom: 1px;
color: #aaa;
}
.categories-list .category .category-icon.add:after {
content: '\f067';
padding-top: 1px;
color: #000;
}
.categories-list .category.add-category {
background: #ffe69a;
}
.categories-list .category:hover {
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.1);
}
.categories-list .category.add-category:hover {
border: 1px solid #fbbc25;
}
.categories-list .category.selected-category:hover {
border: 1px solid #aaa;
background: #eeeeee;
}
.categories-list .category.selected-category:hover:after {
}
.categories-list .category .category-icon.delete:hover:after {
color: #333;
}
.category-list {
list-style: none;
margin: 0;
padding: 0;
}
#select-category-popup {
position: relative;
display: none;
width: 200px;
margin: 30px auto;
box-shadow: 0 0 10px 0 rgba(0,0,0,.5);
padding: 20px;
}
#select-category-popup .close-modal-window {
position: absolute;
top: 20px;
right: 20px;
cursor: pointer;
}
.choose-btn {
width: 100%;
margin-top: 20px;
cursor: pointer;
display: inline-block;
text-align: center;
color: red;
}
<script src="https://use.fontawesome.com/ea0959dcb8.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="categories-list">
<li class="category selected-category">
Action
<span class="category-icon delete"></span>
</li>
<li class="category add-category">
Add category
<span class="category-icon add"></span>
</li>
</ul>
<div id="select-category-popup" class="popup-window">
<a class="close-modal-window">
<i class="fa fa-times" aria-hidden="true"></i>
</a>
<div class="select-block--container">
<ul class="category-list">
<li class="category-item">
<input id="category-action" type="checkbox">
<label for="category-action">Action</label>
</li>
<li class="category-item">
<input id="category-adventure" type="checkbox">
<label for="category-adventure">Adventure</label>
</li>
<li class="category-item">
<input id="category-card" type="checkbox">
<label for="category-card">Card</label>
</li>
</ul>
<span class="choose-btn">Choose</span>
</div>
</div>
在您的代码上,尤其是在干净
js且尽可能清晰的代码上-