Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.19 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.       <meta charset="utf-8" />
  5.         <title>Slideshow</title>
  6.         <style type="text/css">
  7.             #slideshow
  8.             {
  9.                 border: 3px solid black;
  10.                 height: 400px;
  11.                 overflow: hidden;
  12.                 padding: 0;            
  13.                 width: 1200px;
  14.             }
  15.             #slides
  16.             {
  17.                 margin: 0;
  18.                 padding: 0;
  19.                 height: 400px;             
  20.                 position: relative;
  21.                 width: 3600px; /* кол-во элементов на ширину каждого */
  22.             }          
  23.             #slides li
  24.             {
  25.                 float: left;
  26.                 height: 320px;
  27.                 list-style: none;
  28.                 margin: 0;
  29.                 padding: 40px;
  30.                 width: 320px;
  31.             }
  32.             #slides li div
  33.             {
  34.                 height: 100%;
  35.             }
  36.             #slides li.red div { background-color: red; }
  37.             #slides li.orange div { background-color: orange; }
  38.             #slides li.yellow div { background-color: yellow; }
  39.             #slides li.green div { background-color: limegreen; }
  40.             #slides li.lightblue div { background-color: lightblue; }
  41.             #slides li.blue div { background-color: blue; }
  42.             #slides li.purple div { background-color: purple; }
  43.         </style>
  44.         <script type="text/javascript">
  45.             function init() {
  46.                 document.getElementById("left").onclick = function(e) { slide('slides', -10, 60); return false; };
  47.                 document.getElementById("right").onclick = function(e)  { slide('slides', 10, 60); return false; };
  48.             }
  49.            
  50.             function slide(id, speed, minSize) {
  51.                 var ul = document.getElementById(id);
  52.                 var items = ul.getElementsByTagName('li');
  53.                 var width = items[0].clientWidth;
  54.                 var currentLeft = ul.style.pixelLeft;
  55.  
  56.                 // выходим, если достигли конца списка
  57.                 if ((currentLeft >= 0 && speed > 0) || (currentLeft <= (3 - items.length) * width && speed < 0) || speed == 0) {
  58.                     return;
  59.                 }
  60.  
  61.                 var index = Math.abs(currentLeft) / width - speed / Math.abs(speed);
  62.                 var left = items[index].childNodes[0],
  63.                         center = items[index + 1].childNodes[0],
  64.                         right = items[index + 2].childNodes[0];
  65.        
  66.                 var normalHeight = window.getComputedStyle(right).pixelHeight,
  67.                         normalWidth = window.getComputedStyle(right).pixelWidth,
  68.  
  69.                         leftHeightDiff = ((minSize * normalHeight / 100) - window.getComputedStyle(left).pixelHeight) / Math.abs(width / speed),
  70.                         leftWidthDiff = ((minSize * normalWidth / 100) - window.getComputedStyle(left).pixelWidth) / Math.abs(width / speed),
  71.                         rightHeightDiff = ((minSize * normalHeight / 100) - window.getComputedStyle(right).pixelHeight) / Math.abs(width / speed),
  72.                         rightWidthDiff = ((minSize * normalWidth / 100) - window.getComputedStyle(right).pixelWidth) / Math.abs(width / speed),
  73.                         centerHeightDiff = (normalHeight  - window.getComputedStyle(center).pixelHeight) / Math.abs(width / speed),
  74.                         centerWidthDiff = (normalWidth  - window.getComputedStyle(center).pixelWidth) / Math.abs(width / speed);
  75.                
  76.                        
  77.                 function move() {
  78.                     ul.style.pixelLeft += speed;
  79.                    
  80.                     left.style.height = window.getComputedStyle(left).pixelHeight + leftHeightDiff + 'px';
  81.                     left.style.width = window.getComputedStyle(left).pixelWidth + leftWidthDiff + 'px';
  82.                     right.style.height = window.getComputedStyle(right).pixelHeight + rightHeightDiff + 'px';
  83.                     right.style.width = window.getComputedStyle(right).pixelWidth + rightWidthDiff + 'px';
  84.                     center.style.height = window.getComputedStyle(center).pixelHeight + centerHeightDiff + 'px';
  85.                     center.style.width = window.getComputedStyle(center).pixelWidth + centerWidthDiff + 'px';
  86.                    
  87.                     if ((speed > 0 && ul.style.pixelLeft < (currentLeft + width)) || (speed < 0 && ul.style.pixelLeft > (currentLeft - width))) {
  88.                         setTimeout(function() { move(ul, currentLeft, width, speed); }, 10);
  89.                     }
  90.                 }
  91.  
  92.                 move();
  93.             }          
  94.         </script>
  95.     </head>
  96.     <body onload="init()">
  97.         <div id="slideshow">
  98.             <ul id="slides">
  99.                 <li><div></div></li>
  100.                 <li class="red"><div></div></li>
  101.                 <li class="orange"><div></div></li>
  102.                 <li class="yellow"><div></div></li>
  103.                 <li class="green"><div></div></li>
  104.                 <li class="lightblue"><div></div></li>
  105.                 <li class="blue"><div></div></li>
  106.                 <li class="purple"><div></div></li>
  107.                 <li><div></div></li>
  108.             </ul>
  109.         </div>
  110.         <a href="#" id="left">Left</a>
  111.         <a href="#" id="right">Right</a>
  112.     </body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement