Advertisement
Twilypastes

Twily's Slideshow

Jul 12th, 2015
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.01 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Twily's Slideshow</title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  6.  
  7. <style type="text/css">
  8. html,body { margin: 0; padding: 0; background: #000; }
  9.  
  10. .slideshow {
  11.     position: absolute; top: 0; left: 0;
  12.     width: 100%; height: 100%; z-index: 1;
  13.     background: #000 no-repeat center center fixed; background-size: cover;     /* cover || contain */
  14.     opacity: 0; transition: opacity 3s ease;                                    /* Image crossfade time */
  15. }
  16. </style>
  17. <script type="text/javascript">
  18. var $=function(id) { return document.getElementById(id); };
  19.  
  20. // Command to generate imagelist (GNU/Linux) [Requires find, sed and vim]
  21. // $ function list() { echo "var filepath=\"file://"$(pwd)"/\";" && find "$1" -maxdepth 1 -type f -regex ".*\.\(jpg\|jpeg\|png\)" -exec echo "    "\"{}\", \; | sed "s/%/%25/g" | sed "s/\.\///g" | vim -; }; list .
  22. //
  23. // If filenames (or the path) contain '%' they will need to be replaced by '%25' (Eg.: ..%25.. to ..%2525..)
  24. // (The command above does this automatically using sed)
  25. var imagelist=[
  26.     "wallhaven-110491.jpg",
  27.     "wallhaven-123187.jpg",
  28.     "wallhaven-134400.jpg",
  29.     "wallhaven-137115.jpg",
  30.     "wallhaven-149753.jpg",
  31.     "wallhaven-20260.jpg",
  32.     "wallhaven-26620.jpg",
  33.     "wallhaven-31652.jpg",
  34.     "wallhaven-50083.jpg",
  35.     "wallhaven-51234.jpg",
  36.     "wallhaven-54308.jpg",
  37.     "wallhaven-6463.jpg",
  38.     "wallhaven-65157.jpg",
  39.     "wallhaven-6688.jpg",
  40.     "wallhaven-69760.jpg",
  41.     "wallhaven-72147.jpg",
  42.     "wallhaven-82896.jpg",
  43.     "wallhaven-8489.jpg",
  44.     "wallhaven-86566.jpg",
  45. ];
  46.  
  47. var wTimer=5;                                                                   // Seconds before next image
  48. var wOpacity=100;                                                               // 0 (Transparent) - 100 (Opaque)
  49. var filepath="file:///home/guest/Pictures/Wallpapers/wallhaven/";               // Path to find images (filepath+imagelist[x])
  50.  
  51. function init() {
  52.     nextImage();                                                                // Show first image
  53.     if(imagelist.length>1) setInterval("nextImage();",wTimer*1000);             // Run the slideshow
  54. }
  55.  
  56. var wshow="img1",whide="img2",newimg,curimg;
  57. function nextImage() {
  58.     curimg=newimg;
  59.     while(newimg==curimg) newimg=Math.floor(Math.random()*imagelist.length);    // Generate next random image
  60.     (new Image()).src=filepath+imagelist[newimg];                               // Preload next image
  61.  
  62.     whide=[wshow,wshow=whide][0];                                               // Swap values
  63.     $(wshow).style.backgroundImage="url('"+filepath+imagelist[curimg]+"')";     // Show current image
  64.     $(wshow).style.opacity=wOpacity/100;
  65.     $(whide).style.opacity=0;
  66.  
  67.     if(curimg==null) nextImage();                                               // Buffer one image ahead
  68. }
  69. </script>
  70. </head>
  71. <body onload="init();">
  72.  
  73. <div id="img1" class="slideshow"></div>
  74. <div id="img2" class="slideshow"></div>
  75.  
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement