javascript - animate element dynamically on creation -
i want dynamically create divs, append them body , set jquery animation.
this elements created:
function drawspot() {  var myh1 = document.createelement("div");  myh1.style.position = "absolute";  myh1.style.top = getrandom(0,100)+"%";  myh1.style.left = getrandom(0,100)+"%";  myh1.style.width="40px";  myh1.style.height="40px";  $("body").append(myh1);  } and time on appended body, want start animation.
if using jquery, should way:
$('<div>', {     css: {         position:   'absolute',         top:        getrandom(0,100)+'%',         left:       getrandom(0,100)+'%',         width:      '40px',         height:     '40px'     } }).appendto( document.body ).animate({     left:  '100%'  // instance }, 2000); by using .appendto() still have reference original object , able chain methods on it.
ref.: jquery constructor, .appendto(), .animate()
Comments
Post a Comment