Skip to content

Instantly share code, notes, and snippets.

@ilonacodes
Created April 15, 2020 12:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilonacodes/7c3e8c6c537ac76026c2cff922dafd4d to your computer and use it in GitHub Desktop.
Save ilonacodes/7c3e8c6c537ac76026c2cff922dafd4d to your computer and use it in GitHub Desktop.
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