添加评论

This commit is contained in:
2020-07-10 17:49:51 +08:00
parent 0cbd50eeda
commit 80192652ed
6 changed files with 225 additions and 119 deletions

View File

@ -3,7 +3,10 @@ import vditor from 'vditor'
import 'vditor/dist/index.css'
const $tags = document.getElementById('tags')
const floatTop = $tags.offsetTop + $tags.scrollHeight + 30
let floatTop = null
if ($tags) {
floatTop = $tags.offsetTop + $tags.scrollHeight + 30
}
function addEvent (obj, type, fn) {
if (obj.attachEvent) {
@ -24,30 +27,32 @@ window.onload = function () {
// 底部返回顶部按钮
const top = document.getElementById('gotop')
// 滚动一屏幕时显示回到顶部
addEvent(window, 'scroll', function () {
const currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition > window.screen.availHeight ? top.style.display = 'block' : top.style.display = 'none'
if (top) {
// 滚动一屏幕时显示回到顶部
addEvent(window, 'scroll', function () {
const currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition > window.screen.availHeight ? top.style.display = 'block' : top.style.display = 'none'
// 左部导航自动浮动
if (currentPosition > floatTop) {
document.getElementById('navication').style.position = 'fixed'
} else {
document.getElementById('navication').style.position = 'static'
}
})
top.onclick = function () {
var timer = setInterval(function () { // eslint-disable-line
let currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition -= 100
if (currentPosition > 0) {
window.scrollTo(0, currentPosition)
// 左部导航自动浮动
if (currentPosition > floatTop) {
document.getElementById('navication').style.position = 'fixed'
} else {
window.scrollTo(0, 0)
clearInterval(timer)
document.getElementById('navication').style.position = 'static'
}
}, 10)
})
top.onclick = function () {
var timer = setInterval(function () { // eslint-disable-line
let currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition -= 100
if (currentPosition > 0) {
window.scrollTo(0, currentPosition)
} else {
window.scrollTo(0, 0)
clearInterval(timer)
}
}, 10)
}
}
let _hmt = _hmt || [] // eslint-disable-line