按轨迹周期运动

简介: 一、水平方向上的反复运动例如:水平宽度:50px小球直径:6px html结构:                        css样式:.line{position: relative;width: 100px;height: 100px;border-bottom: 1px solid red;left: 100px;top: 100px;}.

一、水平方向上的反复运动
例如:
水平宽度:50px
小球直径:6px


html结构:
    <div id="line" class="line">
        <div id="point" class="point" >
        </div>
    </div>
css样式:
.line{position: relative;width: 100px;height: 100px;border-bottom: 1px solid red;left: 100px;top: 100px;}
.point{width: 6px;height: 6px;background-color: Red;position: absolute;left: 47px;top: 47px;border-radius: 3px;}
js代码:
            var point = document.getElementById("point");
            var line = document.getElementById("line");
            var i = 0, j = 0;
            var b = false;
            setInterval(function () {
                if (i < line.offsetWidth && false == b) {
                    i++;
                    point.style.left = 47 - 50 + i + "px";
                    point.style.top = 47 + 50 + "px";
                }
                if (contline.offsetWidth == i) { b = true; }
                if (i > 0 && true == b) {
                    i--;
                    point.style.left = 47 - 50 + i + "px";
                    point.style.top = 47 + 50 + "px";
                }
                if (0 == i) {
                    b = false;
                }
            }, 60);

View Code
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title>水平周期运动</title>
5 <style type="text/css">
6 .line{position: relative;width: 100px;height: 100px;border-bottom: 1px solid red;left: 100px;top: 100px;}
7 .point{width: 6px;height: 6px;background-color: Red;position: absolute;left: 47px;top: 47px;border-radius: 3px;}
8 </style>
9 <script type="text/javascript">
10 window.onload = function () {
11 var point = document.getElementById("point");
12 var line = document.getElementById("line");
13 var i = 0, j = 0;
14 var b = false;
15 setInterval(function () {
16 if (i < line.offsetWidth && false == b) {
17 i++;
18 point.style.left = 47 - 50 + i + "px";
19 point.style.top = 47 + 50 + "px";
20 }
21 if (contline.offsetWidth == i) {
22 b = true;
23 }
24 if (i > 0 && true == b) {
25 i--;
26 point.style.left = 47 - 50 + i + "px";
27 point.style.top = 47 + 50 + "px";
28 }
29 if (0 == i) {
30 b = false;
31 }
32 }, 60);
33 }
34 </script>
35 </head>
36 <body>
37 <div id="line" class="line">
38 <div id="point" class="point">
39 </div>
40 </div>
41 </body>
42 </html>

二、按长方形(正方形)周长运动
长方形的长和宽分别是150px和100px
小球直径:6px


html结构:
    <div id="rectangle" class="rectangle">
        <div id="point" class="point">
        </div>
    </div>
css样式:
.rectangle{position: relative;width: 150px;height: 100px;border: 1px solid red;left: 100px;top: 100px;}
.point{width: 6px;height: 6px;background-color: Red;position: absolute;left: 47px;top: 47px;border-radius: 3px;}
js代码:

var point = document.getElementById("point");
            var rectangle = document.getElementById("rectangle");
            var i = 0, j = 0;
            setInterval(function () {
                if (i < rectangle.offsetWidth && 0 == j) {
                    i++;
                    point.style.left = 47 - 50 + i + "px";
                    point.style.top = 47 - 50 + j + "px";
                }

                else if (rectangle.offsetWidth == i && j < rectangle.offsetHeight) {
                    j++;
                    point.style.left = 47 - 50 + i + "px";
                    point.style.top = 47 - 50 + j + "px";
                }
                else if (i > 0 && rectangle.offsetHeight == j) {
                    i--;
                    point.style.left = 47 - 50 + i + "px";
                    point.style.top = 47 - 50 + j + "px";
                }
                else {
                    j--;
                    point.style.left = 47 - 50 + i + "px";
                    point.style.top = 47 - 50 + j + "px";
                }
            }, 60);

View Code
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title>水平周期运动</title>
5 <style type="text/css">
6 .rectangle{position: relative;width: 150px;height: 100px;border: 1px solid red;left: 100px;top: 100px;}
7 .point{width: 6px;height: 6px;background-color: Red;position: absolute;left: 47px;top: 47px;border-radius: 3px;}
8 </style>
9 <script type="text/javascript">
10 window.onload = function () {
11 var point = document.getElementById("point");
12 var rectangle = document.getElementById("rectangle");
13 var i = 0, j = 0;
14 setInterval(function () {
15 if (i < rectangle.offsetWidth && 0 == j) {
16 i++;
17 point.style.left = 47 - 50 + i + "px";
18 point.style.top = 47 - 50 + j + "px";
19 }
20
21 else if (rectangle.offsetWidth == i && j < rectangle.offsetHeight) {
22 j++;
23 point.style.left = 47 - 50 + i + "px";
24 point.style.top = 47 - 50 + j + "px";
25 }
26 else if (i > 0 && rectangle.offsetHeight == j) {
27 i--;
28 point.style.left = 47 - 50 + i + "px";
29 point.style.top = 47 - 50 + j + "px";
30 }
31 else {
32 j--;
33 point.style.left = 47 - 50 + i + "px";
34 point.style.top = 47 - 50 + j + "px";
35 }
36 }, 60);
37 }
38 </script>
39 </head>
40 <body>
41 <div id="rectangle" class="rectangle">
42 <div id="point" class="point">
43 </div>
44 </div>
45 </body>
46 </html>

三、按圆形周长运动 2∏R
圆形直径:100px
小球直径:6px

html结构:
    <div class="circle">
        <div id="point" class="point">
        </div>
    </div>
css样式:
.circle{position: relative;width: 100px;height: 100px;border: 1px solid red;left: 100px;top: 100px;border-radius: 50px;}
.point{width: 6px;height: 6px;background-color: Red;position: absolute;left: 47px;top: 47px;border-radius: 3px;}
js代码:
var point = document.getElementById("point");
            var i = 0;
            setInterval(function () {
                if (360 == i) {
                    i = 0;
                    point.style.left = 47 + 50 * Math.cos(0 * 2 * Math.PI / 360) + "px";
                    point.style.top = 47 + 50 * Math.sin(0 * 2 * Math.PI / 360) + "px";
                }
                else {
                    i++;
                    point.style.left = 47 + 50 * Math.cos(i * 2 * Math.PI / 360) + "px";
                    point.style.top = 47 + 50 * Math.sin(i * 2 * Math.PI / 360) + "px";
                }
            }, 60);

View Code
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title>水平周期运动</title>
5 <style type="text/css">
6 .circle{position: relative;width: 100px;height: 100px;border: 1px solid red;left: 100px;top: 100px;border-radius: 50px;}
7 .point{width: 6px;height: 6px;background-color: Red;position: absolute;left: 47px;top: 47px;border-radius: 3px;}
8 </style>
9 <script type="text/javascript">
10 window.onload = function () {
11 var point = document.getElementById("point");
12 var i = 0;
13 setInterval(function () {
14 if (360 == i) {
15 i = 0;
16 point.style.left = 47 + 50 * Math.cos(0 * 2 * Math.PI / 360) + "px";
17 point.style.top = 47 + 50 * Math.sin(0 * 2 * Math.PI / 360) + "px";
18 }
19 else {
20 i++;
21 point.style.left = 47 + 50 * Math.cos(i * 2 * Math.PI / 360) + "px";
22 point.style.top = 47 + 50 * Math.sin(i * 2 * Math.PI / 360) + "px";
23 }
24 }, 60);
25 }
26 </script>
27 </head>
28 <body>
29 <div class="circle">
30 <div id="point" class="point">
31 </div>
32 </div>
33 </body>
34 </html>

四、椭圆周长运动 ∏(a+b)
椭圆长半径:100px、短半径:50px
小球直径:6px

html结构:
    <div class="oval">
        <div id="point" class="point">
        </div>
    </div>
css样式:
.oval{position: relative;width: 200px;height: 100px;border: 1px solid red;left: 100px;top: 100px;border-radius: 100px/50px;}
.point{width: 6px;height: 6px;background-color: Red;position: absolute;left: 47px;top: 47px;border-radius: 3px;}
js代码:
            var point = document.getElementById("point");
            var i = 0;
            setInterval(function () {
                if (360 == i) {
                    i = 0;
                    point.style.left = 97 + 100 * Math.cos(0 * 2 * Math.PI / 360) + "px";
                    point.style.top = 47 + 50 * Math.sin(0 * 2 * Math.PI / 360) + "px";
                }
                else {
                    i++;
                    point.style.left = 97 + 100 * Math.cos(i * 2 * Math.PI / 360) + "px";
                    point.style.top = 47 + 50 * Math.sin(i * 2 * Math.PI / 360) + "px";
                }
            }, 60);

View Code
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title>水平周期运动</title>
5 <style type="text/css">
6 .oval{position: relative;width: 200px;height: 100px;border: 1px solid red;left: 100px;top: 100px;border-radius: 100px/50px;}
7 .point{width: 6px;height: 6px;background-color: Red;position: absolute;left: 47px;top: 47px;border-radius: 3px;}
8 </style>
9 <script type="text/javascript">
10 window.onload = function () {
11 var point = document.getElementById("point");
12 var i = 0;
13 setInterval(function () {
14 if (360 == i) {
15 i = 0;
16 point.style.left = 97 + 100 * Math.cos(0 * 2 * Math.PI / 360) + "px";
17 point.style.top = 47 + 50 * Math.sin(0 * 2 * Math.PI / 360) + "px";
18 }
19 else {
20 i++;
21 point.style.left = 97 + 100 * Math.cos(i * 2 * Math.PI / 360) + "px";
22 point.style.top = 47 + 50 * Math.sin(i * 2 * Math.PI / 360) + "px";
23 }
24 }, 60);
25 }
26 </script>
27 </head>
28 <body>
29 <div class="oval">
30 <div id="point" class="point">
31 </div>
32 </div>
33 </body>
34 </html>





目录
相关文章
|
机器学习/深度学习 人工智能 边缘计算
人工智能语音转文字(Automatic Speech Recognition, ASR)
人工智能语音转文字(Automatic Speech Recognition, ASR)
1507 1
|
小程序 容器 JavaScript
探索uni-app:构建跨平台应用的神奇工具
探索uni-app:构建跨平台应用的神奇工具
|
8月前
|
人工智能 数据可视化 API
2026年阿里云轻量服务器OpenClaw图文攻略|Coding Plan免费API+智谱GLM-5双模型配置避坑指南
2026年,OpenClaw结合阿里云轻量服务器与双大模型(阿里云百炼Coding Plan免费API+智谱GLM-5),已实现“零基础、零代码、全场景”的AI自动化落地。本文完整覆盖**新手零基础阿里云轻量服务器部署OpenClaw(Clawdbot)简单步骤及免费大模型阿里云百炼Coding Plan API配置及避坑指南**,从阿里云秒级部署、双模型自由切换,到核心技能扩展、全场景避坑,全程提供可直接复制的代码与可视化指引,确保新手一次成功、稳定运行。
1489 1
|
12月前
|
搜索推荐
掌握三大核心技巧,快速成为1688运营高手!
1688运营需聚焦三大核心:提升店铺综合权重、优化搜索相关性、挖掘流量价值。通过商品、转化、服务等多维度协同,精准匹配关键词与类目,强化客户体验与复购,系统提升L等级与动销表现,实现曝光、转化双增长。每月复盘,稳步推进,打造高竞争力店铺。
|
安全 Linux
Community Enterprise Operating System
CentOS(Community ENTerprise Operating System)是一个基于Red Hat Enterprise Linux(RHEL)的开源Linux发行版,旨在提供一个免费的、社区支持的操作系统,并与RHEL保持二进制兼容。CentOS最初由Gregory Kurtzer于2004年创建,目标是为用户提供企业级操作系统的功能,同时避免RHEL的订阅费用。 CentOS以其稳定性、长期支持和强大的社区支持而闻名,通常广泛应用于服务器环境,因为它提供了与RHEL相同的性能和功能。在2020年,Red Hat宣布CentOS的开发方向将转向CentOS Stream,这意
605 4
Community Enterprise Operating System
|
机器学习/深度学习 人工智能 自然语言处理
【人工智能】人工智能就业岗位发展方向有哪些?
人工智能领域的岗位多样,涵盖了从技术研发到应用实施、从产品设计到市场运营等各个方面,以下是人工智能就业岗位的主要发展方向
2011 59
|
网络架构
静态路由是什么?
【8月更文挑战第18天】 静态路由是什么?
864 1
|
Shell Python
Python中os模块的常用方法和示例
在Python中,`os`模块提供了与操作系统交互的函数,用于文件和目录管理、路径操作、环境变量等。常用方法包括路径操作(如`os.path.join()`、`os.path.abspath()`)、文件和目录管理(如`os.mkdir()`、`os.remove()`)、环境变量和进程管理(如`os.getenv()`、`os.system()`)以及其他常用功能(如`os.getcwd()`、`os.urandom()`)。
987 0
|
安全 Java Linux
正确认识及掌握时间的用法
时间是一个相对地区而言的概念,因此有一个基准地区,就是本初子午线穿过的地区。了解世界时间相关的概念可以更好地协调全球人们的活动,便于跨越不同地区的时差。比如按照UTC时区划分算,洛杉矶和北京 之间的时间差异是16个小时, 但是一旦洛杉矶启用了夏令时两者之间的时间差异只有15个小时,神奇吗?
1930 0
正确认识及掌握时间的用法
|
Web App开发 数据可视化 JavaScript
动画墙纸:将视频、网页、游戏、模拟器变成windows墙纸——Lively Wallpaper
动画墙纸:将视频、网页、游戏、模拟器变成windows墙纸——Lively Wallpaper
2009 0