当前位置:网站首页>Perfect / buffer motion framework in sentence parsing JS (for beginners)
Perfect / buffer motion framework in sentence parsing JS (for beginners)
2022-07-26 10:26:00 【Xaivor】
1. Perfect motion frame for beginners , still highly necessary Of , So we need to Make a good analysis .
2. Solid foundation , Try to Don't read the notes 了 , Consolidate and review old knowledge !
//js Perfect motion frame
// function ( object ,{style1: The target 1, style2: The target 2}, Exercise time , Function after ending the motion )
function startMove(obj, json, time, fn)
{
clearInterval(obj.iTimer); // Turn off the timer first
var iCur = 0; // First var One iCur A variable's value , namely style Change to the value of , Change value
var iSpeed = 0; // Again var One iSpeed A variable's value , namely style Changing speed value , Variable speed value
obj.iTimer = setInterval(function() // Turn on another self timer
{
var iBtn = true; // Turn on a switch , Give this switch a true Value
for(var attr in json) //for loop , In turn json Array style Value traversal
{
var iTarget = json[attr]; // Assign the target value to iTarget
if(attr == 'opacity') // If style The value is opacity value
{
iCur = Math.round(css(obj, 'opacity') * 100);// First call css() Method to get style Value is assigned to iCur Change value , Then take it first *100, And then round it to the nearest whole
}
else // If style The value is other
{
iCur = parseInt(css(obj, attr));// First call css() Method to get style Value is assigned to iCur Change value , Then round it directly
}
iSpeed = (iTarget - iCur) / time; // Sum the target value with iCur The difference of the change value divided by a variable assigned to iSpeed Variable speed value , This variable can control the speed ,time The bigger it is , The longer the change time
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);// Then use the conditional expression , Round up the shift value
if(iCur != iTarget) // If the change value does not reach the target value , If the target value is reached, it will not enter the judgment statement
{
iBtn = false; // Turn off the switch , Can't turn off the timer , Continue to cycle
if(attr == 'opacity') // If style The value is opacity when
{
obj.style.opacity = (iCur + iSpeed) / 100;// Of changing objects opacity value
obj.style.filter = 'alpha(opacity=' + (iCur + iSpeed) + ')';// Of changing objects filter value
}
else // If style The value is other , Like length and width , Location, etc px Of style value
{
obj.style[attr] = iCur + iSpeed + 'px'; // Change its style value
}
};
};
if(iBtn) // If the switch is true It's on , Just execute the statement
{
clearInterval(obj.iTimer); // off timer
fn && fn.call(obj); // perform fn function
}
}, 30);
};
// How to get the style
function css(obj, attr)
{
if(obj.currentStyle)
{
return obj.currentStyle[attr];
}
else
{
return getComputedStyle(obj, false)[attr];
}
};
3. Copy the above code and save it as startMove.js Script files , Import html Just documents .
4. In need of using js In the code , call startMove() This method , That's all right. . for example :
window.onload = function () {
// A box One button
var aDiv = document.getElementById('box');
var aBtn = document.getElementsByTagName("button")[0];
// Button click event
aBtn.onclick = function () {
// Call the perfect motion frame ( Object of action ,{style1: The target 1, style2: The target 2}, Exercise time , Function after ending the motion )
startMove(aDiv,{
left : 500,
width:1000,
opacity : 40
},30,function () {
alert(" The exercise is over !")
});
}
}
边栏推荐
- Nacos custom service change subscription
- Error in render: "typeerror: cannot read properties of undefined (reading 'length')" --- error when calling interface
- PLC概述
- Review of database -- 3. SQL language
- [C language] LINQ overview
- 数通基础-网络基础知识
- Learning about tensorflow (II)
- 【Halcon视觉】数组
- 关于函数模板描述错误的是(链接格式错误怎么解决)
- 关于模板函数声明与定义的问题[通俗易懂]
猜你喜欢
【Halcon视觉】算子的结构
我们的Web3创业项目,黄了
Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da
Agenda express | list of sub forum agenda on July 27
On the compilation of student management system of C language course (simple version)
Dynamically determine file types through links
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component
Learning about tensor (III)
Our Web3 entrepreneurship project is yellow
equals与==的区别
随机推荐
【socket】三次握手是在listen中完成,accept只从完成连接的队列中拿出一个连接
【Halcon视觉】数组
[Halcon vision] polar coordinate transformation
Data communication foundation - layer 2 switching principle
面试第二家公司的面试题及答案(二)
js翻页、kkpager.js翻页
Okaleido生态核心权益OKA,尽在聚变Mining模式
Wechat official account release reminder (wechat official account template message interface)
Network related journals and conferences in CS
Controller返回JSON数据
[Halcon vision] image gray change
Dynamically determine file types through links
mysql 进不去了怎么办
将json文件中数组转换为struct
canvas上传图片base64-有裁剪功能-Jcrop.js
Some descriptions of DS V2 push down in spark
Comparison of packet capturing tools fiddler and Wireshark
Learning about opencv (3)
Learning about opencv (2)
[Halcon vision] programming logic