Skip to content

Instantly share code, notes, and snippets.

@andipollok
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save andipollok/8844467 to your computer and use it in GitHub Desktop.

Select an option

Save andipollok/8844467 to your computer and use it in GitHub Desktop.
Text Hover Effect

Simple mouseover on a text, changing its color and font size.

<!DOCTYPE html>
<meta charset="utf-8">
<title></title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<style>
text {
font-family: Helvetica, Arial, sans-serif;
cursor: pointer;
}
</style>
<body>
<script>
var width = 960,
height = 500;
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height);
svg.append('text')
.text('Touch me')
.attr('x', width/2)
.attr('y', height/2)
.attr('font-size', 20)
.attr('fill', '#333')
.style('text-anchor', 'middle')
.on('mouseover', function(d,i) {
d3.select(this).transition()
.ease('cubic-out')
.duration('200')
.attr('font-size', 32)
.attr('fill', 'springgreen');
})
.on('mouseout', function(d,i) {
d3.select(this).transition()
.ease('cubic-out')
.duration('200')
.attr('font-size', 20)
.attr('fill', '#333');
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment