html5+css3+BUI实现抽屉式小说章节展示效果,点遮罩可自动关闭章节抽屉
html5+css3+BUI实现抽屉式小说章节展示效果
html
<div class="drawer drawer-init">
<div class="drawer-bg" style="display: none;"> </div>
<div class="cata-title">
章节目录
<em><i class="icon-close"></i></em>
</div>
<div class="drawer-content">
<ul b-template="book.tplChapterList(book.bookinfo.chapter)"></ul>
</div>
</div>
获取数据
post("{:furl('v1/bookdetail', ['id' => $bid], true, 'api')}", {}, function(result) {
if(result.code == 0) {
that.bookinfo = result.data || [];
} else {
bui.hint(result.msg);
}
});
js
tplChapterList: function (data) {
let that = this;
let html = "";
data.forEach(function (item, i) {
if(that.bookinfo.chapter_url == item.chapter_url) {
html += `<li class="active"><a href="${item.chapter_url}">${item.title}</a></li>`;
} else {
html += `<li><a href="${item.chapter_url}">${item.title}</a></li>`;
}
});
return html;
}
事件
$('.drawer-bg').click(function() {
$('.drawer').removeClass('drawer-open').addClass('drawer-init').find('.drawer-bg').hide();
})
$('.cata-title em').click(function() {
$('.drawer').removeClass('drawer-open').addClass('drawer-init').find('.drawer-bg').hide();
})
css
.drawer {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100%;
z-index: 9999;
-webkit-transition: opacity .6s, -webkit-transform .38s ease-in-out;
transition: opacity .6s, -webkit-transform .38s ease-in-out;
transition: transform .38s ease-in-out, opacity .6s;
transition: transform .38s ease-in-out, opacity .6s, -webkit-transform .38s ease-in-out;
will-change: transform;
overflow: hidden;
}
.drawer-bg {
background-color: rgba(0, 0, 0, .4);
width: 100vw;
height: 100vh;
position: fixed;
left: 0;
top: 0;
}
.drawer-init {
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
opacity: 0;
}
.drawer-open {
-webkit-transform: translateX(0);
transform: translateX(0);
opacity: 1;
}
获取项目
第一步:克隆你本地 (如果不用git的可以在代码仓库上角打包下载代码,然后解压上传到服务器)
git clone https://gitee.com/paheng/feiniao.git
第二步:进入目录
cd feiniao
第三步:下载PHP依赖包
composer install
上一篇: PHP入门笔记
下一篇: 仿威客任务网站开发的