Mini-Circle Game - Code

Mini-Circle Game - Code

  • Author / Uploaded
  • Elena

Citation preview

$(document).ready(function(){

var changeColor = function() { var red = Math.round(Math.random() * 255); var green = Math.round(Math.random() * 255); var blue = Math.round(Math.random() * 255); return "rgb(" + red + ","+ green + ","+ blue + ")"; };

var xPosition = 0; var yPosition = 0;

var x = 100; $(document).click(function(e){ clone(e); $("#circle").css('background-color', changeColor());

x += 5; $("#circle").css("width", + x + "px" ); $("#circle").css("height", + x + "px" );

xPosition = e.pageX-x/2; yPosition = e.pageY-x/2;

$("#circle").animate({top: yPosition , left: xPosition});

});

$(document).dblclick(function(e) {

x -= 15; $("#circle").css("width", + x + "px" ); $("#circle").css("height", + x + "px" );

xPosition = e.pageX-x/2; yPosition = e.pageY-x/2;

$("#circle").animate({top: yPosition , left: xPosition}); });

function clone() { var newCircle = $('#circle').clone( true ); newCircle.removeAttr('id'); newCircle.attr("class", "circle"); $("body").append(newCircle); }

});