Эксклюзивно для
рони, чисто из любви к искусству
<!DOCTYPE HTML>
<html>
<head>
<title>Перемещение круга</title>
<style type="text/css" >
.svgcircle
{
position: absolute;
}
.circle, .rect, .ellipse
{ -webkit-transition:all 3s cubic-bezier(0, 0, 1, 1);
-moz-transition:all 3s cubic-bezier(0, 0, 1, 1);
-o-transition:all 3s cubic-bezier(0, 0, 1, 1);
transition:all 3s cubic-bezier(0, 0, 1, 1);
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
function createAndsetNewAttr(elem,elemNew) {
$(elem).attr({
cx: Math.random() * 500,
cy: Math.random() * 500,
x: Math.random() * 500,
y: Math.random() * 500,
fill: randomRGBColor()
});
var r = document.createElementNS("http://www.w3.org/2000/svg", elemNew);
$(r).attr({
class: elemNew,
x: Math.random() * 500,
y: Math.random() * 500,
cx: Math.random() * 500,
cy: Math.random() * 500,
fill: randomRGBColor()
});
switch (elemNew) {
case "rect":
$(r).attr({
width: "35",
height: "35"
});
break;
case "ellipse":
$(r).attr({
rx: "50",
ry: "25"
});
break;
case "circle":
$(r).attr({
r: "35"
});
}
$('svg').append(r);
}
function randomRGBComponent() {
return Math.round(Math.random() * 255);
}
function randomRGBColor() {
return 'rgb(' + randomRGBComponent() + ', ' + randomRGBComponent() + ', ' + randomRGBComponent() + ')';
}
$("html").on("click", ".circle", function () {
createAndsetNewAttr(this, "rect");
});
$("html").on("click", ".rect", function () {
createAndsetNewAttr(this, "ellipse");
});
$("html").on("click", ".ellipse", function () {
createAndsetNewAttr(this, "circle");
});
</script>
</head>
<body>
<svg version="1.1" baseProfile="full" width ="600" height ="600" class="svgcircle">
<circle class="circle" cx="300" cy="300" r="35" fill="red"/>
</svg>
</body>
</html>
Только не говорите, что Math.random() * 500 можно заменить функцией