Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Select the poem tag
  2. let poemNumber = 0
  3. const poemTag = document.querySelector('div.poem h1')
  4.  
  5. //Content for the poemTag
  6. const poems = [
  7.   'My human shell enclosed in bark',
  8.   "It's cold inside this cocoon",
  9.   'I go to a funeral everyday',
  10.   'Merging under the white heat',
  11.   'My love is unholy'
  12. ]
  13.  
  14. //Pick a random line from poems
  15. const randomPoem = function() {
  16.   poemNumber = Math.floor(Math.random() * poems.length)
  17.   poemTag.innerHTML = poems[poemNumber]
  18. }
  19.  
  20. //change the content of the poem tag
  21. document.addEventListener('DOMContentLoaded', function() {
  22.   randomPoem()
  23. })
  24.  
  25. //random image Anordnung
  26. const imageList = [
  27.   '_dsf4699.jpg',
  28.   '_dsf4744.jpg',
  29.   '_dsf4785.jpg',
  30.   '_dsf1410.jpg',
  31.   '_dsf4694.jpg',
  32.   '_dsf4749.jpg'
  33. ]
  34. const picturesSection = document.querySelector('section#pictures')
  35.  
  36. //Random parameters
  37. const parameterLeft = ['0px', '5%', '10%']
  38. const parameterRight = ['0px', '0px', '0px', '5%']
  39. const parameterTop = ['200px', '50px', '100px', '150px', '250px', '300px']
  40. const parameterBottom = ['0px', '5%']
  41. const parameterWidth = ['35%', '30%', '20%', '20%', '20%', '40%']
  42.  
  43.  
  44. const randomImages = function() {
  45.   for(var i = imageList.length -1; i > 0; i--) {
  46.     var j = Math.floor(Math.random() * (i+1))
  47.     var temp = imageList[i]
  48.     imageList[i] = imageList[j]
  49.     imageList[j] = temp
  50.   }
  51.  
  52.   imageList.forEach(function(image) {
  53.     const img = document.createElement('img')
  54.     img.setAttribute('src', image)
  55.  
  56.     img.style.marginTop = parameterTop[Math.floor(Math.random() * parameterTop.length)]
  57.     img.style.marginRight = parameterRight[Math.floor(Math.random() * parameterRight.length)]
  58.     img.style.marginBottom = parameterBottom[Math.floor(Math.random() * parameterBottom.length)]
  59.     img.style.marginLeft = parameterLeft[Math.floor(Math.random() * parameterLeft.length)]
  60.     img.style.width = parameterWidth[Math.floor(Math.random() * parameterWidth.length)]
  61.  
  62.     picturesSection.appendChild(img)
  63.   })
  64. }
  65.  
  66. document.addEventListener('DOMContentLoaded', function() {
  67.   randomImages()
  68. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement