1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| var CompteurNotes = 0;
function ajtNote(){
// comptage des notes
console.log('note ajoutée');
CompteurNotes++;
// Création du post-it
var note = document.createElement('div');
note.className = 'note';
note.setAttribute('style','margin:'+margin()+'; transform:'+rotate());
note.style.background = color();
// Création d'un titre pour la note
var title = document.createElement('input');
title.type = 'text';
title.placeholder = 'Ajouter un titre';
title.className = 'titreNote';
title.style.background = note.style.background;
note.appendChild(title);
// Création d'une zone de texte pour écrire
var zoneTexte = document.createElement('textarea');
zoneTexte.className = 'contenuNote';
zoneTexte.placeholder = 'Ecrire quelque chose ici...';
zoneTexte.style.background = note.style.background;
note.appendChild(zoneTexte);
// Création du bouton supprimer
var delBtn = document.createElement('button');
delBtn.className = 'delBtn';
delBtn.onmousedown = SupprNote;
var txt = document.createElement('p');
txt.className = 'croix';
var x = document.createTextNode('x');
txt.appendChild(x);
delBtn.appendChild(txt);
note.appendChild(delBtn);
// numérotation des notes et des boutons supprimer
note.id = 'Note n°' + CompteurNotes;
delBtn.id = 'Btn n°' + CompteurNotes;
// ajout du post-it à l'élément body
var MEP = document.getElementById('#board').appendChild(note);
// Création de la fonction de suppression du post-it
function SupprNote(){
var element = document.getElementById(note.id); element. parentNode. removeChild(element);
console.log('note n°'+note.id + ' supprimée');
}
// Fonction personnalisation post-it
// marge aléatoire
function margin(){
var random_margin = ["-1px","1px", "5px", "10px","15px","20px"];
return random_margin[Math.floor(Math.random() * random_margin.length)];
}
// rotation aléatoire
function rotate(){
var random_degree = ["rotate(3deg)","rotate(1deg)","rotate(-1deg)","rotate(-3deg)","rotate(-4deg)", "rotate(5deg)"];
return random_degree[Math.floor(Math.random() * random_degree.length)];
}
function color(){
var i = Math.floor(Math.random() * 7);
var random_colors = ["#c2ff3d","#ff3de8","#3dc2ff","#04e022","#bc83e6","#ebb328"];
if(i > random_colors.length - 1){
i = 0;
}
return random_colors[i];
}
}
// Création de la fonction permettant de suppprimer tous les post-it d'un coup
function Clear(){
document.getElementById('#board').innerHTML = "";
} |
Partager