Advertisement
Guest User

Slide Show em Jquery HTML5 CSS3

a guest
Mar 18th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.13 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pt-br">
  3.  
  4. <head>
  5.     <meta charset="utf-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7.  
  8.     <!-- HTML5Shiv -->
  9.     <!--[if lt IE 9]>
  10.            <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  11.          <![endif]-->
  12.  
  13.     <link rel="stylesheet" type="text/css" href="css/style.css">
  14.  
  15.     <title>SlideShow com JQuery</title>
  16.  
  17. </head>
  18.  
  19. <body>
  20.  
  21.     <div id="slider">
  22.  
  23.         <!--Controladores do slide-->
  24.         <a href="http://" class="control_next">&gt;</a>
  25.         <a href="http://" class="control_prev">&lt;</a>
  26.  
  27.         <ul>
  28.             <li>
  29.                 <a href="http://" id="imagen1">
  30.                     <img src="imagens/imagem1.jpeg">
  31.                 </a>
  32.             </li>
  33.  
  34.             <li>
  35.                 <a href="http://" id="imagen2">
  36.                     <img src="imagens/imagem2.jpeg">
  37.                 </a>
  38.             </li>
  39.  
  40.             <li>
  41.                 <a href="http://" id="imagen3">
  42.                     <img src="imagens/imagem3.jpeg">
  43.                 </a>
  44.             </li>
  45.  
  46.             <li>
  47.                 <a href="http://" id="imagen4">
  48.                     <img src="imagens/imagem4.jpeg">
  49.                 </a>
  50.             </li>
  51.  
  52.         </ul><!--ul-->
  53.  
  54.     </div><!--#slider-->
  55.  
  56.  
  57.     <!--JQuery 3.6.4-->
  58.     <script src="js/jquery.min.js"></script>
  59.  
  60.     <script>
  61.         $(function () {
  62.             $('#slider').change(function () {
  63.                 setInterval(function () {
  64.                     moveRight();
  65.                 }, 3000);
  66.             });
  67.  
  68.             var slideCount = $('#slider ul li').length();
  69.  
  70.             var slideWidth = $('#slider ul li').width();
  71.  
  72.             var slideHeight = $('#slider ul li').height();
  73.  
  74.             //Calculando a largura e altura do Slide na Ul
  75.             var sliderUlWidth = slideCount * slideWidth;
  76.  
  77.             $('#slider').css({
  78.                 width: slideWidth,
  79.                 height: slideHeight
  80.             });
  81.  
  82.             $('#slider ul').css({
  83.                 width: sliderUlWidth,
  84.                 height: -slideWidth
  85.             });
  86.  
  87.             $('#slider ul li:last-child').prependTo('#slider ul');
  88.  
  89.             function moveLeft() {
  90.                 $('#slider ul').animate({
  91.  
  92.                     left: +slideWidth
  93.  
  94.                 }, 200, function () {
  95.  
  96.                     $('#slider ul li:last-child').prependTo('#slider ul');
  97.  
  98.                     $('#slider ul').css('left', '');
  99.  
  100.                 });
  101.             }
  102.  
  103.             function moveRight() {
  104.                 $('#slider ul').animate({
  105.  
  106.                     left: -slideWidth
  107.  
  108.                 }, 200, function () {
  109.  
  110.                     $('#slider ul li:first-child').appendTo('#slider ul');
  111.  
  112.                     $('#slider ul').css('left', '');
  113.  
  114.                 });
  115.             }
  116.  
  117.  
  118.             $('a.control_prev').click(function () {
  119.                 moveLeft();
  120.             });
  121.  
  122.             $('a.control_next').click(function () {
  123.                 moveRight();
  124.             });
  125.         });
  126.     </script>
  127.  
  128. </body>
  129.  
  130. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement