Skip to content

Instantly share code, notes, and snippets.

@ilonacodes

ilonacodes/index.js

Created Apr 15, 2020
Embed
What would you like to do?
VanillaJS — index.js
const card = document.querySelector(".card");
const hideLinkPreview = () => {
return card.style.display = 'none';
};
const showLinkPreview = event => {
const image = event.currentTarget.getAttribute("data-image");
card.querySelector('img').setAttribute("src", image);
const title = event.currentTarget.getAttribute("data-title");
card.querySelector('h5').textContent = title;
const text = event.currentTarget.getAttribute("data-text");
card.querySelector('p').textContent = text;
event.currentTarget.appendChild(card);
return card.style.display = 'inline-block';
};
document.querySelectorAll(".link-with-preview").forEach(el => {
el.addEventListener("mouseover", showLinkPreview);
el.addEventListener("mouseleave", hideLinkPreview)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment