Skip to content

Instantly share code, notes, and snippets.

@benpickles
Created October 20, 2011 19:21
Show Gist options
  • Save benpickles/1302039 to your computer and use it in GitHub Desktop.
Save benpickles/1302039 to your computer and use it in GitHub Desktop.
Peity events example
<!DOCTYPE html>
<html>
<head>
<title>Peity events example</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://benpickles.github.com/peity/jquery.peity.js"></script>
<script>
// Apply Peity once.
$(function() {
$("#pie").peity("pie")
})
// Update the pie every few seconds.
setInterval(function() {
var homepossession = Math.floor(Math.random() * 100)
// Peity pies only deal with two numbers (at the moment) and work like
// they are read so 3 out of 5 would be written like 3/5 rather than 3/2
// (which would mean 3 out of 2!). So no need for this.
// var awaypossession = 100 - homepossession;
// Peity is already applied to the element so just need to change the text
// and trigger change on the element, it'll take care of the redraw.
$('#pie').text(homepossession + "/100").change()
}, 3000)
</script>
</head>
<body>
<span id="pie">2/5</span>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment