当前位置:网站首页>了解预加载和懒加载、学会缓动动画
了解预加载和懒加载、学会缓动动画
2022-07-26 03:08:00 【M78_国产007】
预加载:在加载页面时会有很多链接、图片等,提前加载资源--同源加载的优化。
懒加载: 资源先不加载 等条件成立时再加载,如我们的网页滑倒某个位置就开始加载。
现在先了解一下就行。
缓动动画
匀速改变元素的样式是匀速动画;非匀速的改变元素的样式就是缓动动画。
要实现缓动动画非常简单,记住一个公式就行:
设定值=当前值+(目标值-当前值)*百分比
配合计时器使用,每次加的越来越少,实现缓动。
小例子:
底部缓动滑入
<style>
.box{
margin: 100px auto;
width: 300px;
position: relative;
height: 450px;
overflow: hidden;
}
img{
width: 300px;
}
.info{
position: absolute;
top: 450px;
height:150px;
width: 100%;
background-color: rgba(255,255,255,0.8);
display: flex;
flex-direction: column;
justify-content: space-around
}
.info div{
height: 40px;
color: gray;
text-align: center;
}
.info div span{
color: orange;
margin-left:20px ;
}
</style>
<div class="box">
<img src="../img/明星7.jpg" alt="">
<div class="info">
<div>古力娜扎 <span>年薪:***<span></div>
<div>演员 舞者 少男杀手</div>
<div>入职***有限公司</div>
</div>
</div>
<script>
var info=document.querySelector(".info")
var box=document.querySelector(".box")
var timer1=null
var timer2=null
box.onmouseenter=function(){
clearInterval(timer2)
timer1 = setInterval(function(){
var nowcsstop=parseInt(window.getComputedStyle(info).top)
// console.log(nowcsstop);
info.style.top=nowcsstop +(300-nowcsstop)*0.5+"px"
},100)
}
box.onmouseleave=function(){
clearInterval(timer1)
timer2 = setInterval(function(){
info.style.top=parseInt(info.style.top)+(450-parseInt(info.style.top))*0.5+"px"
},100)
}
</script>边栏推荐
- Parallelloopbody in opencv
- canvas——矩形的绘制——柱状图的制作
- Dataframe sorting: datetime format splitting; Delete a specific line; Group integration.
- How to design test cases according to the requirements of login testing?
- How to design automated test cases?
- 【无标题】
- 信息系统项目管理师必背核心考点(五十)合同内容约定不明确规定
- Keyboardtraffic, a tool developed by myself to solve CTF USB keyboard traffic
- Image recognition (VI) | activation function
- Skill list of image processing experts
猜你喜欢

MySQL tutorial: MySQL database learning classic (from getting started to mastering)

The difference between the world wide web, the Internet and the Internet

Win11 method of changing disk drive letter

Swin Transformer【Backbone】

LeetCode·每日一题·剑指 Offer || 115.重建序列·拓扑排序

canvas——绘制曲线——挂钟,饼图,五角星
![[untitled]](/img/6f/a2cd98af7a8de469e5311422b48afe.png)
[untitled]

Opening method of win11 microphone permission

STM32 - DMA notes
![[translation] cloud like internal load balancer for kubernetes?](/img/e5/f003ebed05a94d2936cfef5617f745.jpg)
[translation] cloud like internal load balancer for kubernetes?
随机推荐
LeetCode·83双周赛·6128.最好的扑克手牌·模拟
Opening method of win11 microphone permission
From the annual reports of major apps, we can see that user portraits - labels know you better than you do
JVM内存模型解析
Three years of software testing experience, salary has been stuck at 10K, how to improve and develop automated testing?
The source of everything, the choice of code branching strategy
Swin Transformer【Backbone】
这种动态规划你见过吗——状态机动态规划之股票问题(上)
Opencv 以指定格式保存图片
Win11麦克风权限的开启方法
Neo4j import CSV data error: neo4j load CSV error: couldn't load the external resource
Managing databases in a hybrid cloud: eight key considerations
持续交付和DevOps是一对好基友
Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?
多线程编程
GoLang日志编程系统
如何根据登录测试的需求设计测试用例?
Win11大小写提示图标怎么关闭?Win11大小写提示图标的关闭方法
移位距离和假设的应用
[C Advanced] deeply explore the storage of data (in-depth analysis + interpretation of typical examples)