Home > Web Front-end > JS Tutorial > body text

js special effects: js realizes the effect code of somersault cloud

不言
Release: 2018-08-14 16:50:12
Original
2569 people have browsed it

The content of this article is about js special effects: the js effect code for realizing somersault cloud, which has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Understand the principle of easing animation

<!DOCTYPE html>
<!--create by ydj on 2018-08-12-->
<html>
	<head>
		<meta charset="UTF-8">
		<title>筋斗云</title>
		<style>
        *{margin: 0; padding: 0;}
        ul {list-style:none;}
        body {
            background-color: #000;
        }
        .nav {
            width: 800px;
            height: 42px;
            background:url("images/rss.png") no-repeat right center #fff;
            margin: 100px auto;
            border-radius: 5px;
            position: relative; 
        }
        .cloud {
            width: 83px;
            height: 42px;
            position: absolute;
            top: 0;
            left: 0;
            background: url("images/cloud.gif") no-repeat;
        }
        .nav ul {
            position: absolute;
            top: 0;
            left: 0;
        }
        .nav li {
            float: left;
            width: 83px;
            height: 42px;
            line-height: 42px;
            text-align: center;
            color: #000;
            cursor: pointer;
        }
    </style>
	</head>
	<body>
		<p class="nav" id="nav">
			<span class="cloud" id="cloud"></span>
			<ul>
				<li>AI数据中心</li>
				<li>财务中心</li>
				<li>事业中心</li>
				<li>陆兵学院</li>
				<li>供应中心</li>
				<li>总经办</li>
				<li>品牌中心</li>
				<li>人力中心</li>
			</ul>
		</p>
	</body>
</html>
<script>
	// 获取元素
	var cloud = document.getElementById("cloud");
	var nav = document.getElementById("nav");
	var lis = nav.children[1].children;
	// 记录点击时的位置
	var current = 0;
	for (var i = 0; i < lis.length; i++) {
		lis[i].onmouseover = function(){
			target = this.offsetLeft;
		}
		lis[i].onclick = function(){
			current = this.offsetLeft;
		}
		lis[i].onmouseout = function(){
			target = current;
		}
	}
	// 缓动动画
	var leader = 0,target =0;
	setInterval(function(){
		leader = leader + (target -leader)/10;
		cloud.style.left = leader + "px";
	},10);
	
</script>
Copy after login

Effect

##Related recommendations:

How to use css Use js to make the text on the page flicker? (Example)

Ajax upload file and display the file upload process progress bar code

The above is the detailed content of js special effects: js realizes the effect code of somersault cloud. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template