首页
wjlink
视频
投稿
直播
壁纸
更多
留言
统计
LINK
Search
1
Python 爬取YouTube某个频道下的所有视频信息
178 阅读
2
宝塔面板绑定域名套上cloudflare – 实现cdn访问拯救你的IP
128 阅读
3
Paypal外区账户/国际版绑大陆手机号注册教程
102 阅读
4
windows 使用 FFmpeg 按大小或时间来批量分割视频
85 阅读
5
苹果CMS(MACCMS)如何在标题中随机插入关键词
84 阅读
技術類
自媒体
調查
问卷调查
美國站
英國站
注册丨登录
Search
标签搜索
wordpress
V2Ray
vps
苹果cms
面板
php
宝塔
ipfs
DD
脚本
语言
上传
判断
Youtube
cdn
ip
AI
HTML
1
2
Hou
累计撰写
67
篇文章
累计收到
0
条评论
今日撰写
0
篇文章
️
首页
分类
技術類
自媒体
調查
问卷调查
美國站
英國站
页面
wjlink
视频
投稿
直播
壁纸
留言
统计
LINK
登录丨注册
搜索到
2
篇与
的结果
2024-11-08
为网站添加网页加载动画
网页加载的时候先显示一个动画,等加载完成后,再显示网页,这样做过度比较自然。用户体验感比较好。原理原理是,给网页顶部放一个元素,元素占满全屏,加载完成后,再通过JS移除这个元素即可。简单在网页顶部写个代码,一个div,作为容器,然后设置样式,给占满全屏。<style> .loading-animations { background: #666; position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 9999; } </style> <div class="loading-animations" id="loading-warp"></div>接下来,监听网页事件,加载完成后,给移除他,或者设置样式display为none。网页加载完成事件有window.onload,但是这个要覆盖其他的方法,所以使用监听器最好 window.addEventListener('load', function () { let loader = document.getElementById("loading-warp"); loader.style.display = "none" });效果如下:看得出来,比较生硬。并且没有任何东西,就是全屏展示,然后等待网页加载完消失。这个时候,修改一下样式。给网页添加一个渐变效果,在消失的时候,缓慢消失。修改上面的style,加入了一个transition动画,和opacity透明度。默认为1 .loading-animations { background: #666; position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 9999; transition: 1s; opacity: 1; } .loading-animations-out { opacity: 0; } 等网页加载完成后,给元素添加上loading-animations-out类,就可以实现渐变消失。消失以后,等待1秒,将元素移除即可。 window.addEventListener('load', function () { let loader = document.getElementById("loading-warp"); loader.className = "loading-animations loading-animations-out";//使用渐隐的方法淡出loading page setTimeout(() => { loader.style.display = "none" }, 1000); });那么,实现效果会这样进阶都这么做了,那么再搞个加载图就完事大吉了。不过对于前端来说,使用图片,会再一次请求服务器。用户第一次访问的时候,图片可能加载不出来。所以,使用svg输出内容,或者使用css动画,最合适。既然CSS动画了,那就看一个网站吧:https://labs.danielcardoso.net/load-awesome/animations.html网站包含了很多CSS加载动画,html内容和css内容都贴出来了。甚至还有不同样式和大小的代码接下来,再修改代码内容。主要在样式里面,将元素容器设置为flex,垂直居中。(选了一个简单的动画,不然代码有点多。)<style> .loading-animations { background: #666; position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; transition: 1s; opacity: 1; } .la-ball-clip-rotate, .la-ball-clip-rotate > div { position: relative; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .la-ball-clip-rotate { display: block; font-size: 0; color: #fff; } .la-ball-clip-rotate.la-dark { color: #333; } .la-ball-clip-rotate > div { display: inline-block; float: none; background-color: currentColor; border: 0 solid currentColor; } .la-ball-clip-rotate { width: 32px; height: 32px; } .la-ball-clip-rotate > div { width: 32px; height: 32px; background: transparent; border-width: 2px; border-bottom-color: transparent; border-radius: 100%; -webkit-animation: ball-clip-rotate .75s linear infinite; -moz-animation: ball-clip-rotate .75s linear infinite; -o-animation: ball-clip-rotate .75s linear infinite; animation: ball-clip-rotate .75s linear infinite; } .la-ball-clip-rotate.la-sm { width: 16px; height: 16px; } .la-ball-clip-rotate.la-sm > div { width: 16px; height: 16px; border-width: 1px; } .la-ball-clip-rotate.la-2x { width: 64px; height: 64px; } .la-ball-clip-rotate.la-2x > div { width: 64px; height: 64px; border-width: 4px; } .la-ball-clip-rotate.la-3x { width: 96px; height: 96px; } .la-ball-clip-rotate.la-3x > div { width: 96px; height: 96px; border-width: 6px; } /* * Animation */ @-webkit-keyframes ball-clip-rotate { 0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); } 50% { -webkit-transform: rotate(180deg); transform: rotate(180deg); } 100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); } } @-moz-keyframes ball-clip-rotate { 0% { -moz-transform: rotate(0deg); transform: rotate(0deg); } 50% { -moz-transform: rotate(180deg); transform: rotate(180deg); } 100% { -moz-transform: rotate(360deg); transform: rotate(360deg); } } @-o-keyframes ball-clip-rotate { 0% { -o-transform: rotate(0deg); transform: rotate(0deg); } 50% { -o-transform: rotate(180deg); transform: rotate(180deg); } 100% { -o-transform: rotate(360deg); transform: rotate(360deg); } } @keyframes ball-clip-rotate { 0% { -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); } 50% { -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -o-transform: rotate(180deg); transform: rotate(180deg); } 100% { -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -o-transform: rotate(360deg); transform: rotate(360deg); } } </style> <div class="loading-animations" id="loading-warp"> <div class="la-ball-clip-rotate"> <div></div> </div> </div>这样,效果就比较不错了。当然,还有很多优化的,例如背景颜色,加载样式大小什么的。转载于:https://www.lovestu.com/loading-animation.html
2024年11月08日
17 阅读
0 评论
0 点赞
HTML两栏实现左侧内容可滚动,右侧列表固定跟随布局
HTML实现左侧内容可滚动,右侧列表固定布局<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title>HTML实现左侧内容可滚动,右侧列表固定布局</title> <style type="text/css"> html,body{ width:100%; height:100%; } html,body,header,footer,div,section{ padding:0; margin:0; } .clearfix:after{ content:''; display:block; clear:both; height:0; visibility:hidden; } .clearfix{ zoom:1; } .sec-wrapper{ min-height:100%; } .head-top{ width:100%; height:100px; line-height:100px; text-align:center; font-size:16px; color:#fff; background:#E74445; } .main-section{ padding-bottom:100px; margin:20px auto; } .foot{ width:100%; height:100px; line-height:100px; text-align:center; font-size:16px; color:#fff; background:#528FEA; margin-top:-100px; } .div-wrapper{ width:1200px; margin:0 auto; background:#F4F6F9; position:relative; } .cont-left{ width:900px; float:left; margin-right:10px; } .list-right{ float:left; } .cont-item{ width:100%; height:200px; background:tan; margin-top:10px; } .box-fixed{ width:290px; height:600px; padding-top:20px; background-color:#89A1C5; position:relative; top:0px; text-align:center; color:#fff; } .tab_fix_bottom { position: absolute; bottom: 0px; top: auto; } .tab_fix{ position:fixed; } </style> </head> <body> <section class="sec-wrapper"> <header class="head-top">页面头部</header> <section class="main-section"> <div class="div-wrapper clearfix"> <div class="cont-left"> <div class="cont-item"></div> <div class="cont-item"></div> <div class="cont-item"></div> <div class="cont-item"></div> <div class="cont-item"></div> <div class="cont-item"></div> <div class="cont-item"></div> <div class="cont-item"></div> </div> <div class="list-right"> <div class="box-fixed">新闻列表</div> </div> </div> </section> </section> <footer class="foot">页面底部</footer> <script src="/style/js/jquery-2.1.1.min.js"></script> <script type="text/javascript"> $(function(){ var fheight = $('.foot').height() + 30; // 获取底部及底部上方边距的总高度 var boxfixed = $('.box-fixed'); // 获取固定容器的jquery对象 $(window).scroll(function() { var scrollTop = $(window).scrollTop(); // 获取滚动条滚动的高度 var contLeftTop = $('.cont-left').offset().top+20; // 右侧列表相对于文档的高度 var scrollBottom = $(document).height() - $(window).scrollTop() - boxfixed.height(); if (scrollTop >= contLeftTop) { if (scrollBottom > fheight) { // 滚动条距离底部的距离大于fheight,添加tab_fix类,否则添加tab_fix_bottom类 boxfixed.removeClass("tab_fix_bottom").addClass('tab_fix'); } else { boxfixed.removeClass('tab_fix').addClass("tab_fix_bottom"); } } else if (scrollTop < contLeftTop) { boxfixed.removeClass('tab_fix').removeClass("tab_fix_bottom"); } }); }); </script> </body> </html>
2024年02月29日
7 阅读
0 评论
0 点赞