Created
April 15, 2020 12:17
-
-
Save ilonacodes/7c3e8c6c537ac76026c2cff922dafd4d to your computer and use it in GitHub Desktop.
VanillaJS — index.js
This file contains 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 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