请在这里查看示例 ☞ curve示例
对Math方法不了解的请看另一篇博客:
http://blog.csdn.net/u011500781/article/details/51407593
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<script src="js/jquery-1.11.3.min.js"></script>
<style>
* {margin: 0; padding: 0;}
body, html {width: 100%; height: 100%;}
div {display: inline-block; outline: 1px solid blue;}
.start {position: absolute; top: 300px; left: 50px;}
.end {position: absolute; top: 50px; left: 1000px;}
</style>
</head>
<body>
<div class="start">开始</div>
<div class="end">结束</div>
<input type="text" value="0.002">
<script>
$(function() {
$('body').on('click', function(e) {
$('.start:not(:first)').remove();
var $endPos = $('.end').position();
var startLeft = e.clientX,
startTop = e.clientY,
endLeft = $endPos.left,
endTop = $endPos.top;
var a = +$('input').val();
var x = startLeft;
var y = 0;
b = (startTop-endTop-a*startLeft*startLeft+a*endLeft*endLeft)/(startLeft-endLeft);
c = endTop-a*endLeft*endLeft-b*endLeft;
console.log('y=('+a+'*x*x)+('+b+'*x)+('+c+')');
var timer = setInterval(function() {
x += 10;
if(x == endLeft) {
clearInterval(timer);
}
var $div = $('.start:last').clone().appendTo('body');
y = a*x*x+b*x+c;
$div.css({
'left': x,
'top': y,
});
}, 20);
});
})
</script>
</body>
</html>