deus-abencoe
Version:
Um pacote com utilitários para facilitar o desenvolvimento front-end de projetos brasileiros
36 lines (30 loc) • 1.2 kB
JavaScript
document.querySelectorAll('.copyButton').forEach(function (button) {
button.addEventListener('click', function () {
var code = this.previousElementSibling.innerText;
var textarea = document.createElement('textarea');
textarea.value = code;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
alert('Código copiado para a área de transferência!');
});
});
// Get the button
let mybutton = document.getElementById("backToTopBtn");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE, and Opera
}