增加回到顶部按钮

This commit is contained in:
wolegca 2019-10-19 21:56:07 +08:00
parent 28c51e58e6
commit db6940f715
8 changed files with 210 additions and 120 deletions

View File

@ -34,7 +34,7 @@ permalink: /404.html
</label> </label>
<div class="NotFound"> <div class="NotFound">
<!--NOT FOUND-->
</div> </div>
</div> </div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

View File

@ -396,29 +396,82 @@ body {
.loading span:nth-of-type(1) { .loading span:nth-of-type(1) {
animation-delay: .125s animation-delay: .125s
} }
.loading span:nth-of-type(2) { .loading span:nth-of-type(2) {
animation-delay: .250s animation-delay: .250s
} }
.loading span:nth-of-type(3) { .loading span:nth-of-type(3) {
animation-delay: .375s animation-delay: .375s
} }
.loading span:nth-of-type(4) { .loading span:nth-of-type(4) {
animation-delay: .5s animation-delay: .5s
} }
.loading span:nth-of-type(5) { .loading span:nth-of-type(5) {
animation-delay: .625s animation-delay: .625s
} }
.loading span:nth-of-type(6) { .loading span:nth-of-type(6) {
animation-delay: .750s animation-delay: .750s
} }
.top {
display: block;
position: fixed;
bottom: 10px;
right: 25px;
height: 40px;
width: 40px;
border: 10px;
background: #ccc;
cursor: pointer;
border: 2px solid gray;
transition: border .3s ease;
border-radius: 50%;
opacity: 0;
}
.top:hover {
border: 2px solid white;
}
.topBtn:before {
content: '';
display: block;
position: absolute;
width: 50%;
height: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(45deg);
border-left: 5px solid rgb(30, 30, 30);
border-top: 5px solid rgb(30, 30, 30);
}
.topBtn:after {
content: '';
display: block;
position: absolute;
width: 50%;
height: 50%;
top: 80%;
left: 50%;
transform: translate(-50%, -50%) rotate(45deg);
border-left: 5px solid rgb(30, 30, 30);
border-top: 5px solid rgb(30, 30, 30);
}
@keyframes load { @keyframes load {
0% { 0% {
transform: rotate(0deg) transform: rotate(0deg)
} }
50% { 50% {
transform: rotate(360deg); transform: rotate(360deg);
} }
100% { 100% {
transform: rotate(360deg); transform: rotate(360deg);
} }

View File

@ -51,6 +51,9 @@
<span></span> <span></span>
<span></span> <span></span>
</div> </div>
<div class="top" title="回到顶部">
<span class="topBtn"></span>
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="js/drag.js"></script> <script src="js/drag.js"></script>
<script src="js/initialize.js"></script> <script src="js/initialize.js"></script>

View File

@ -2,10 +2,41 @@ $(function () {
window.onselectstart = block; window.onselectstart = block;
window.ontouchstart = block; window.ontouchstart = block;
window.ondragstart = block; window.ondragstart = block;
var topElem = $('.top'),
isCssed = false,
docTop;
toggleTop();
$('.msg-header').Drag($('.msg-container')); $('.msg-header').Drag($('.msg-container'));
$('.menu-container ul li span').on('click', function () { $('.menu-container ul li span').on('click', function () {
message.alert('这里是', '<div style="text-align:right"><div style="font-size:28px;height:70px;padding-top:20px;text-align:center">AHPU-老中医</div>的博客&nbsp;&nbsp;&nbsp;</div>'); message.alert('这里是', '<div style="text-align:right"><div style="font-size:28px;height:70px;padding-top:20px;text-align:center">AHPU-老中医</div>的博客&nbsp;&nbsp;&nbsp;</div>');
}); });
topElem.on('click', function () {
$('html,body').animate({
scrollTop: '0px'
}, 300);
});
window.onscroll = toggleTop;
function toggleTop() {
docTop = document.documentElement.scrollTop;
if (docTop >= 300 && !isCssed) {
topElem.css({
"display": "block",
"animation": "fadeIn .2s forwards"
});
isCssed = true;
} else if (docTop < 300 && isCssed) {
topElem.css({
"animation": "fadeOut .2s forwards"
});
setTimeout(function () {
topElem.css({
"display": "none"
});
}, 200);
isCssed = false;
}
}
function block() { function block() {
return false; return false;

View File

@ -51,6 +51,9 @@
<span></span> <span></span>
<span></span> <span></span>
</div> </div>
<div class="top" title="回到顶部">
<span class="topBtn"></span>
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="js/drag.js"></script> <script src="js/drag.js"></script>
<script src="js/initialize.js"></script> <script src="js/initialize.js"></script>