新增功能:页面下拉小箭头平滑跳转到内容部分
# 前言
实现一个下拉小箭头,在全屏界面直接跳转到内容的部分。(模仿 sakura 主题的下拉小箭头)
# 实现下拉小箭头
箭头图标使用的
ic i-angle-down图标,使用动态效果.up-down,名字啥的还是自己起,这里我的命名比较随意。代码还是在找到 themes->shoka->source->js->_app,以下修改还是在这里修改。找到
global.js,大概 17 行左右,新增:var angleBtn = $('#angle');
找到
pjax.js,大概 20 行左右,仿照 toolBtn,在下方新增:if(!angleBtn) {
angleBtn = siteHeader.createChild('div', {
id: 'angle',
innerHTML: '<span><i class="ic i-angle-down" aria-hidden="true"></i></span>'
});
}在下方新增事件监听器:
angleBtn.addEventListener('click',headertopdown);
在
sidebar.js大概 220 行左右,可以在const goToCommentHandle = function () {
pageScroll($('#comments'));
}下方,新增:
const headertopdown = function () {
pageScroll($('#main'));
}这里直接调用的跳转评论区的函数
pageScroll修改下 css 问题,在 themes->shoka->source->css->_common->outline->header->header.styl 中最后 (@import... 之前) 新增:
/* 首页下拉箭头 */#angle {position: absolute;bottom: 10vh;left: 50%;cursor: pointer;z-index: 5;transform: translateX(-50%);}@media (max-width: 860px) {#angle {bottom: 8vh;}}#angle i {font-size: 35px;color: #fff;@extend .up-down;}
完成!