Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created June 16, 2013 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/5790309 to your computer and use it in GitHub Desktop.
Save enjalot/5790309 to your computer and use it in GitHub Desktop.
papa face
{"description":"papa face","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"face.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12},"mac.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/sfsy1kF.png"}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
var svg = d3.select("svg");
var bg = svg.append("rect")
.attr({
width: "100%",
height: "100%",
opacity: 0
})
var duration = 1000;
var macScale = 1.4;
var papaScale = 0.5;
var mac = svg.select("#mac")
.attr("transform", "scale(" + macScale + ")")
.each(moveToFront)
var macface = svg.select("#face")
.attr("transform", "scale(" + macScale + ")")
.each(moveToFront)
.attr("opacity", 1)
var papaface = svg.select("#papaface")
.attr("stroke", "#000000")
.attr("transform", "translate(" + [98, 66] + ")scale(" + papaScale + ")")
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0)
.each(moveToFront)
function moveToFront() {
this.parentNode.appendChild(this);
}
bg.on("mouseover", function() {
macface.transition()
.duration(duration)
.attr("opacity", 0)
papaface.selectAll("path")
.attr("stroke-opacity", 1)
.attr("stroke-dasharray", function() {
return "0," + this.getTotalLength();
})
.transition()
.delay(duration)
.duration(duration)
.attrTween("stroke-dasharray", tweenDash)
.transition()
.duration(duration)
.attr("fill-opacity", 1)
})
bg.on("mouseout", function() {
papaface.selectAll("path")
.transition()
.duration(duration)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0)
macface.transition()
.delay(duration)
.duration(duration)
.attr("opacity", 1)
})
function tweenDash() {
var l = this.getTotalLength(),
i = d3.interpolateString("0," + l, l + "," + l);
return function(t) { return i(t); };
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment