Created
November 16, 2017 19:08
-
-
Save limscoder/863e1bf6ff9c7aae16e20a2fd849b9ea to your computer and use it in GitHub Desktop.
D3 animations
This file contains hidden or 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
const userList = d3.select('ul.app-user-list'); | |
const userSelection = userList.selectAll('li.app-user') | |
.data(users); | |
const updateUsers = userSelection; | |
const enterUsers = userSelection.enter(); | |
const exitUsers = userSelection.exit(); | |
// blend from old color to new color | |
updateUsers.transition() | |
.duration(500) | |
.style('color', d => (d.role === 'person' ? 'green' : 'orange')) | |
// render with opacity 0, then blend to opacity 1 | |
enterUsers.append('li') | |
.text(d => d.name) | |
.style('opacity', 1) | |
.transition() | |
.duration(500) | |
.style('opacity', 1) | |
// blend to opacity 0, then remove elements | |
exitUsers.append('li') | |
.text(d => d.name) | |
.transition() | |
.duration(500) | |
.style('opacity', 0) | |
.on('end', () => exitUsers.remove()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment