当前位置:网站首页>Use js to complete the text and move it on the screen according to the numbers in the input box
Use js to complete the text and move it on the screen according to the numbers in the input box
2022-04-22 15:55:00 【The rain is shallow and the wind sings】
The basic case is javascript dom Programming art no 10 Chapter animation effect , On this basis, the input box and the function of moving according to the input box are added

The first two characters will move to a position according to the timer , Enter the following width and height whoa Will move to the specified location
The file structure is as follows

addLoadEvent.js
function addLoadEvent(func){
var onload=window.onload
if(typeof onload!='function'){
window.onload=func;
}else{
window.onload=function(){
onload();
func();
}
}
}
moveElement.js
function moveElement(elementID,final_x,final_y,interval){
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x && ypos == final_y) {
return true;
}
if (xpos < final_x) {
xpos++;
}
if (xpos > final_x) {
xpos--;
}
if (ypos < final_y) {
ypos++;
}
if (ypos > final_y) {
ypos--;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
movement = setTimeout(repeat,interval);
}
positionMessage.js
function positionMessage(){
if(!document.getElementById)return false
if (!document.getElementById("message")) return false;
var elem = document.getElementById("message");
elem.style.position = "absolute";
elem.style.left = "50px";
elem.style.top = "100px";
moveElement("message",125,25,20);
if (!document.getElementById("message2")) return false;
var elem = document.getElementById("message2");
elem.style.position = "absolute";
elem.style.left = "50px";
elem.style.top = "50px";
moveElement("message2",125,75,20);
}
reMoveElement=function(){
var Height=document.getElementById("Height");
var Width=document.getElementById("Width");
moveElement("message",Height.value,Width.value,20);
return false ;
}
addLoadEvent(positionMessage);
message.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="scripts/addLoadEvent.js"></script>
<script type="text/javascript" src="scripts/positionMessage.js"></script>
<script type="text/javascript" src="scripts/moveElement.js"></script>
<title>Document</title>
</head>
<body>
<p id="message">whee!</p>
<p id="message2">whoa!</p>
<form >
Height : <input id="Height" type="number" name="Height" />
Width: <input id="Width" type="number" name="Width" />
<input type="submit" value=" Submit " onclick="reMoveElement();return false ;" />
<!-- οnclick= " moveElement('message',Height,Width.,20)" -->
</form>
</body>
</html>
版权声明
本文为[The rain is shallow and the wind sings]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221552258994.html
边栏推荐
- Practice of radical TLS security configuration based on traifik
- BrokenPipeError: [Errno 32] Broken pipe
- Redis optimization series (I) building redis master-slave based on docker
- 阿里云国际版设置电子邮件托管教程详解
- 这个陀螺仪的精度太高了,还是建议禁止使用吧。
- Altium designer除了GND以外的Nets自动布线
- [writing] thesis writing skills
- JSP echo
- 哈希表篇(二)
- 悟空的私藏「架构』书籍推荐
猜你喜欢

SAP UI5 应用开发教程之七十一 - SAP UI5 页面的嵌套路由试读版

Abbexa丨4E-BP1 细胞 ELISA 试剂盒说明书

SAP UI5 应用开发教程之七十一 - SAP UI5 页面的嵌套路由

SAP UI5 数据类型(data type) 学习笔记

这个陀螺仪的精度太高了,还是建议禁止使用吧。

Dataset之CASIA-WebFace:CASIA-WebFace 数据集的简介、安装、使用方法之详细攻略

年薪37w带12人团队,内推腾讯被拒了。。。
![引入文件路径问题-$_SERVER[‘DOCUMENT_ROOT‘]代表网站根目录](/img/e0/cc889bc10bad51d39e33e4ffdc8202.png)
引入文件路径问题-$_SERVER[‘DOCUMENT_ROOT‘]代表网站根目录

Fe of mL: combined with a case of kaggle competition, study the thinking framework of feature engineering

Alibaba P9 handwritten 39 module redis core notes. I had a successful interview and got a salary increase of 7K
随机推荐
SQL statement - Multi - table Associated Query
Sending non-protected broadcast
Jmeter 存取Sql Server带有逗号‘,‘的数据到csv文件
Fourier analysis and filtering
Crystal Chem 大豆 ELISA 试剂盒 II说明书
Redis simple storage folder
這個API Hub厲害了,收錄了釘釘企業微信等開放Api,還能直接調試 !
Short link generator, ADF ly、shorte. st、ouo. io、adfoc. Which is better and what are the differences
企业级知识管理(KM)建设方法及过程
短链接生成器,adf.ly、shorte.st、ouo.io、adfoc.us哪个更好,有哪些区别
[writing] thesis writing skills
短视频平台搭建,移动端商品下单、购买过程的实现
Greenplum【代码分享 01】实现replace insert或insert on conflict类似on duplicate key update批量入库数据(合并插入无则新增有则更新)
Dongfeng Nissan recalls some Xiaoke with potential safety hazards
How can AI intelligent video technology be applied to the scene of daily maintenance and supervision of cultural relics and historic buildings?
Spark基础学习笔记23:DataFrame与Dataset
短视频平台开发,自定义一个弹窗样式和内容
redis常见面试题有哪些?redis集群面试题及答案整理
近期BSN开发常见问题答疑
Ansible practical tips - batch patrol site URL status