Trying to keep the David Bowie head moving as long as your javascript is running with setInterval().
Last active
August 29, 2015 14:02
-
-
Save mpmckenna8/0659f124bc68c1233a62 to your computer and use it in GitHub Desktop.
setInterval() to make a function keep repeating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.floor{ | |
background:violet; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.js"></script> | |
<script src="threeBowie.js"> </script> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = d3.select('body').append('svg').attr('width', 720).attr('height',270).attr('class','floor'); | |
var daves = [1,2,3,4] | |
var xpos = 40 | |
// this is what appends some pictures to my svg | |
svg.selectAll('.bows') | |
.data(daves) | |
.enter() | |
.append('image') | |
.attr('xlink:href', '/mpmckenna8/raw/f0abe7ae10eef35972bd/icon_21660.svg') | |
.attr('x', function(d){ | |
return 70 * d | |
}) | |
.attr('y', 40) | |
.attr('width',100) | |
.attr('height',100) | |
.attr('class','bows'); | |
function dance (){ | |
svg.selectAll('.bows') | |
.transition() | |
.delay(500) | |
.attr('x',function(d){ | |
return Math.random() *720 -29; | |
}) | |
.attr('y',function(d){ | |
console.log(this.x) | |
return Math.random() *200 -30; | |
}) | |
.duration(5000) | |
}; | |
d3.select('svg') | |
.on('click',function(){ | |
return dance()} | |
) | |
setInterval(dance,6000) | |
dance() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment