更改图像幻灯片上的图像组织

时间:2018-02-23 17:32:48

标签: javascript html css

我创建了一个图片幻灯片,如下所示:



jQuery(document).ready(function($) {

  $('#checkbox').change(function() {
    setInterval(function() {
      moveRight();
    }, 3000);
  });

  var slideCount = $('#slider ul li').length;
  var slideWidth = $('#slider ul li').width();
  var slideHeight = $('#slider ul li').height();
  var sliderUlWidth = slideCount * slideWidth;

  $('#slider').css({
    width: slideWidth,
    height: slideHeight
  });

  $('#slider ul').css({
    width: sliderUlWidth,
    marginLeft: -slideWidth
  });

  $('#slider ul li:last-child').prependTo('#slider ul');

  function moveLeft() {
    $('#slider ul').animate({
      left: +slideWidth
    }, 200, function() {
      $('#slider ul li:last-child').prependTo('#slider ul');
      $('#slider ul').css('left', '');
    });
  };

  function moveRight() {
    $('#slider ul').animate({
      left: -slideWidth
    }, 200, function() {
      $('#slider ul li:first-child').appendTo('#slider ul');
      $('#slider ul').css('left', '');
    });
  };

  $('a.control_prev').click(function() {
    moveLeft();
  });

  $('a.control_next').click(function() {
    moveRight();
  });

});

@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,300,600);
html {
  border-top: 5px solid #fff;
  color: #2a2a2a;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Open Sans';
}

h1 {
  color: #fff;
  text-align: center;
  font-weight: 300;
}

#slider {
  position: relative;
  overflow: hidden;
  margin: 20px auto 0 auto;
  border-radius: 4px;
}

#slider ul {
  position: relative;
  margin: 0;
  padding: 0;
  height: 200px;
  list-style: none;
}

#slider ul li {
  position: relative;
  display: block;
  float: left;
  margin: 0;
  padding: 0;
  width: 500px;
  height: 300px;
  background: #ccc;
  text-align: center;
  line-height: 300px;
}

a.control_prev,
a.control_next {
  position: absolute;
  z-index: 999;
  padding: 0% 0%;
  background: #2a2a2a;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 18px;
  opacity: 0.1;
  cursor: pointer;
  top: 0;
  display: block;
  width: 50%;
  height: 100%;
}

a.control_prev:hover,
a.control_next:hover {
  -webkit-transition: all 0.2s ease;
}

a.control_prev {}

a.control_next {
  right: 0;
}

.slider_option {
  position: relative;
  margin: 10px auto;
  width: 160px;
  font-size: 18px;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Very Simple Slider</title>



  <link rel="stylesheet" href="css/style.css">


</head>

<body>
  <h1>&nbsp;</h1>
  <div id="slider">
    <a href="#" class="control_next"></a>
    <a href="#" class="control_prev"></a>
    <ul>
      <li><img src="https://orig00.deviantart.net/e3bb/f/2012/155/0/c/naruto_unleashed_by_sketch_gfx-d529cho.png"></li>
      <li><img src="https://assets.rbl.ms/6450955/980x.jpg"></li>
      <li><img src="http://tampascene.com/images/new-images/parks-weedonisland.jpg"></li>
    </ul>
  </div>

  <div class="slider_option"> </div>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>



  <script src="js/index.js"></script>




</body>

</html>
&#13;
&#13;
&#13;

我想重新安排图片如下: enter image description here

我已尝试将更多图像包含在内,图像最终出现故障并且无法正常工作我也尝试缩小尺寸,但如果有人有任何指示或想法,它们仍然会出现在不同的视图中,请告诉我。

如果你能告诉我如何修改它,那就太棒了我不介意如果它在JS或CSS中,只要它完成工作我会非常感激。

如果这个问题需要改进,那么只是试图告诉我而不仅仅是贬低我不会伤害我只有13年而且还在提前学习谢谢。

1 个答案:

答案 0 :(得分:1)

我在javascript和css上做了一些更改,特别是在宽度和高度上。

jQuery(document).ready(function($) {

  $('#checkbox').change(function() {
    setInterval(function() {
      moveRight();
    }, 3000);
  });

  var slideCount = $('#slider ul li').length;
  var slideWidth = $('#slider ul li').width();
  var sliderUlWidth = slideCount * slideWidth;

  $('#slider').css({
    width: parseInt(slideWidth) * 3 +"px",
  });

  $('#slider ul').css({
    width: sliderUlWidth
  });

  $('#slider ul li:last-child').prependTo('#slider ul');

  function moveLeft() {
    $('#slider ul').animate({
      left: +slideWidth
    }, 200, function() {
      $('#slider ul li:last-child').prependTo('#slider ul');
      $('#slider ul').css('left', '');
    });
  };

  function moveRight() {
    $('#slider ul').animate({
      left: -slideWidth
    }, 200, function() {
      $('#slider ul li:first-child').appendTo('#slider ul');
      $('#slider ul').css('left', '');
    });
  };

  $('a.control_prev').click(function() {
    moveLeft();
  });

  $('a.control_next').click(function() {
    moveRight();
  });

});
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,300,600);
html {
  border-top: 5px solid #fff;
  color: #2a2a2a;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Open Sans';
}

h1 {
  color: #fff;
  text-align: center;
  font-weight: 300;
}

#slider {
  position: relative;
  overflow: hidden;
  margin: 20px auto 0 auto;
  border-radius: 4px;
}

#slider ul {
  position: relative;
  margin: 0;
  padding: 0;
  height: auto;
  list-style: none;
}
#slider ul li img{
  max-width:100%;
  line-height: 0;
}
#slider ul li {
  position: relative;
  display: block;
  float: left;
  margin: 0;
  padding: 0;
  width: 33.33%;
  height: auto;
  background: #ccc;
  text-align: center;
  line-height: 0;
}

a.control_prev,
a.control_next {
  position: absolute;
  z-index: 999;
  padding: 0% 0%;
  background: #2a2a2a;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 18px;
  opacity: 0.1;
  cursor: pointer;
  top: 0;
  display: block;
  width: 33.33%;
  height: 100%;
}

a.control_prev:hover,
a.control_next:hover {
  -webkit-transition: all 0.2s ease;
}

a.control_prev {}

a.control_next {
  right: 0;
}

.slider_option {
  position: relative;
  margin: 10px auto;
  width: 160px;
  font-size: 18px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Very Simple Slider</title>



  <link rel="stylesheet" href="css/style.css">


</head>

<body>
  <h1>&nbsp;</h1>
  <div id="slider">
    <a href="#" class="control_next"></a>
    <a href="#" class="control_prev"></a>
    <ul>
      <li><img src="https://orig00.deviantart.net/e3bb/f/2012/155/0/c/naruto_unleashed_by_sketch_gfx-d529cho.png"></li>
      <li><img src="https://assets.rbl.ms/6450955/980x.jpg"></li>
      <li><img src="http://tampascene.com/images/new-images/parks-weedonisland.jpg"></li>
    </ul>
  </div>

  <div class="slider_option"> </div>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>



  <script src="js/index.js"></script>




</body>

</html>