<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
//id为要旋转的id,speed速度,radius半径,startx起始点的x坐标,starty起始点的y坐标
function animateCircle(id, speed, radius, startx, starty, phi) {
if (!phi) { phi = 0 };
var int = 2 * (Math.PI) / speed;
phi = (phi >= 2 * (Math.PI)) ? 0 : (phi + int);
var $m = startx - radius * Math.cos(phi);
var $n = starty - radius * Math.sin(phi);
$(id).animate({
marginLeft: $m + 'px',
marginTop: $n + 'px'
}, 1, function() {
animateCircle.call(this, id, speed, radius, startx, starty, phi)
}
);
};
$(document).ready(function() {
animateCircle('#friends', 200, 100, 400, 250);
});
</script>
</head>
<body>
<div id="friends" style="position:absolute">a</p>
</body>
</html>
转自:http://stackoverflow.com/questions/10551380/how-to-make-an-image-move-in-a-circular-path-using-jquery/10551585#10551585
如果要实现每转一圈半径不断增大,螺旋式旋转效果可以改写成
$(id).animate({
marginLeft: $m + 'px',
marginTop: $n + 'px'
}, 1, function() {
animateCircle.call(this, id, speed, ++radius, startx, starty, phi) //半径不断增大
}
);
如果想定到具体的点或者范围不在转可以改成
function animateCircle(id, speed, radius, startx, starty, phi) {
if (!phi) { phi = 0 };
var int = 2 * (Math.PI) / speed;
phi = (phi >= 2 * (Math.PI)) ? 0 : (phi + int);
var $m = startx - radius * Math.cos(phi);
var $n = starty - radius * Math.sin(phi);
$(id).animate({
left: $m + 'px',
top: $n + 'px'
}, 1, function() {
if($m <= 400){//如果left小于400px,则继续转动,否则不再调用
animateCircle.call(this, id, speed, ++radius, startx, starty, phi);
}
}
);
};
分享到:
相关推荐
How to make mistakes in Python
How to make mistakes in python
How to Make Your Own Keylogger in C++ Programming Language 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
本文是有关如何从头开始编写,测试和运行C ++和Assembly的非常简单的操作系统的指南。
How to Create a Database in Python using SQL Lite 3 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
How to Make Sense of Any Mess: Information Architecture for Everybody Abby Covert Everything is getting more complex. It is easy to be overwhelmed by the amount of information we encounter each ...
This demonstrates how to display an image transparently on the form. An excellent example.
MBA CASE, HOW TO MAKE YOUR CASE IN 30 SECOND OR LESS
How to make an embedded controller for…——实时冗余系统zip,How to make an embedded controller for…——实时冗余系统
Learn to build e-commerce sites using PHP by installing a server using WAMP, configuring MySQL for your product database, creating your product database and tables, and writing the required ...
how to get an image in java
How to access particular cell in gridview using jQuery How to filter GridView records using jQuery How to search through GridView records using jQuery GET ASP.NET GridView Cell value using jQuery ...
How-to-Make-Mistakes-in-Python.pdf
How to Make an Operating System from Scratch (Samy Pesse) .pdf
This one-of-a-kind new resource introduces IT architecture to professionals looking for guidance to embark on the successful path to become an IT architect. This book defines the various types of IT ...
Web Hacking 101: How to Make Money Hacking Ethically By 作者: Peter Yaworski Pub Date: 2018 ISBN: n/a Pages: 255 Language: English Format: PDF Size: 10 Mb With a Foreword written by HackerOne Co-...
How to play an AVI in a status bar.
17. Is it possible to make an image automation if you are not in a Citrix environment? 18. When is it recommended to use containers? 19. What happens if the AddHeaders option is checked in the Read ...
This is an excellent example of how to make a paint program with a few extras.
讲解了怎么做一个成功的英语口语的presentation. 1.the purpose of presentation 2.the elements of an effective presentation 3.The effective delivery of information 4.......