{
const width = 400,
height = 40p0,
margin = { top: 5, right: 5, bottom: 5, left: 5 },
side = 30;
const students = [
{
name: "Adithi",
img: "https://ca.slack-edge.com/T0WA5NWKG-U05Q6NBPU4R-b3196d8d3fcd-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Aimee",
img: "https://ca.slack-edge.com/T0WA5NWKG-U067V9B20GM-7082a64518b0-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Chloe",
img: "https://ca.slack-edge.com/T0WA5NWKG-U05EASBCY66-03459d5ab8c0-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Dan",
img: "https://ca.slack-edge.com/T0WA5NWKG-U052DATFX38-5c53b05cb8fa-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Eric",
img: "https://ca.slack-edge.com/T0WA5NWKG-U06832BDQQ1-g7ce1229c2f5-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Eun-Hae",
img: "https://ca.slack-edge.com/T0WA5NWKG-U064Y7T9TSB-3f2a30e3dec7-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Gina",
img: "https://ca.slack-edge.com/T0WA5NWKG-U05P7ELB5JT-234ebd6606ce-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Hyung",
img: "https://ca.slack-edge.com/T0WA5NWKG-U0670A26K9N-8e04cc130e00-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Indu",
img: "https://ca.slack-edge.com/T0WA5NWKG-U051DPE4M6J-57554b5b4667-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Jae",
img: "https://ca.slack-edge.com/T0WA5NWKG-U05GB5K23HR-cfce9c7d625f-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Jesse",
img: "https://ca.slack-edge.com/T0WA5NWKG-U06A19FTUE4-7756fc6b8a81-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Joshua",
img: "https://ca.slack-edge.com/T0WA5NWKG-U053JE2TRNG-fd164ed7389a-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Justin",
img: "https://ca.slack-edge.com/T0WA5NWKG-U0686D72Q56-bb3952bc0528-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Mohamed",
img: "https://ca.slack-edge.com/T0WA5NWKG-U05K82D9ALC-c1f938d66e6b-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Ryan",
img: "https://ca.slack-edge.com/T0WA5NWKG-U05QHMAFZ4Z-db8e37c6e608-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Subhasis",
img: "https://ca.slack-edge.com/T0WA5NWKG-U06BYJXL7V1-b93ba674e9dc-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Yifan",
img: "https://ca.slack-edge.com/T0WA5NWKG-U07CUQDE6PP-a0b482e70d25-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
},
{
name: "Zakaria",
img: "https://ca.slack-edge.com/T0WA5NWKG-U05385DR3QW-e9423c222785-72",
var1: Math.random() * 150,
var2: Math.random() * 2.0
}
];
const images = d3
.select("svg")
.append("g")
.selectAll("image")
.data(students)
.join("image")
.attr("href", (d) => d.img)
.attr("x", (d) => width / 2 - 15)
.attr("y", (d) => height / 2 - 15)
.attr("width", side)
.attr("height", side)
.attr("preserveAspectRatio", "xMidYMin slice");
function moveLeft() {
images.transition().duration(750).attr("x", 20);
}
function moveX() {
images
.transition()
.duration(750)
.attr(
"x",
(d) => Math.random() * (width - margin.left - margin.right - side / 2)
);
}
function moveY() {
images
.transition()
.duration(750)
.attr(
"y",
(d) => Math.random() * (height - margin.top - margin.bottom - side / 2)
);
}
//window.addEventListener("scroll", function (e) {
// console.log(window.scrollY)
//})
const callbacks = [
moveLeft,
moveX,
moveY,
moveLeft,
moveX,
moveY,
moveLeft,
moveX,
moveY,
moveLeft,
moveX
];
const steps = d3.selectAll(".step");
// instantiate the scrollama
const scroller = scrollama();
// setup the instance, pass callback functions
scroller
.setup({
step: ".step"
})
.onStepEnter((response) => {
// { element, index, direction }
callbacks[response.index]();
steps.style("opacity", 0.1);
d3.select(response.element).style("opacity", 1.0);
console.log("enter", response);
})
.onStepExit((response) => {
// { element, index, direction }
console.log("exit", response);
});
// setup resize event
window.addEventListener("resize", scroller.resize);
}