图像在旋转木马中组合

时间:2017-12-27 15:00:44

标签: javascript html css

图像在旋转木马中合并。 我用html写了



how many rows x column <input type="number" min="1" value="2" class="count-row"> X <input min="1" value="3" type="number" class="count-column"> <button class="btn-create">create</button> <button class="btn-show">show DOM</button>
<form action="test.php" method="post">
<table></table>
</form>


<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
&#13;
$(function(){
    $('#carousel').each(function(){
        var slideTime = 200;
        var delayTime = 2000;

        var carouselWidth = $(this).width();
        var carouselHeight = $(this).height();
        $(this).append('<div id="carousel_prev"></div><div id="carousel_next"></div>');
        $(this).children('ul').wrapAll('<div id="carousel_wrap"><div id="carousel_move"></div></div>');

        $('#carousel_wrap').css({
            width: (carouselWidth),
            height: (carouselHeight),
            position: 'relative',
            overflow: 'hidden'
        });

        var listWidth = parseInt($('#carousel_move').children('ul').children('li').css('width'));
        var listCount = $('#carousel_move').children('ul').children('li').length;

        var ulWidth = (listWidth)*(listCount);

        $('#carousel_move').css({
            top: '0',
            left: -(ulWidth),
            width: ((ulWidth)*3),
            height: (carouselHeight),
            position: 'absolute'
        });

        $('#carousel_wrap ul').css({
            width: (ulWidth),
            float: 'left'
        });
        $('#carousel_wrap ul').each(function(){
            $(this).clone().prependTo('#carousel_move');
            $(this).clone().appendTo('#carousel_move');
        });

        carouselPosition();

        $('#carousel_prev').click(function(){
            clearInterval(setTimer);
            $('#carousel_move:not(:animated)').animate({left: '+=' + (listWidth)},slideTime,function(){
                carouselPosition();
            });
            timer();
        });

        $('#carousel_next').click(function(){
            clearInterval(setTimer);
            $('#carousel_move:not(:animated)').animate({left: '-=' + (listWidth)},slideTime,function(){
                carouselPosition();
            });
            timer();
        });

        function carouselPosition(){
            var ulLeft = parseInt($('#carousel_move').css('left'));
            var maskWidth = (carouselWidth) - ((listWidth)*(listCount));
            if(ulLeft == ((-(ulWidth))*2) || ulLeft == ((-(ulWidth))*2)+1) {
                $('#carousel_move').css({left:-(ulWidth)});
            } else if(ulLeft == 0) {
                $('#carousel_move').css({left:-(ulWidth)});
            };
        };

        timer();

        function timer() {
            setTimer = setInterval(function(){
                $('#carousel_next').click();
            },delayTime);
        };

    });
});
&#13;
* {
  margin: 0;
  padding: 0;
}

.menu {
  background-color: gray;
  width: 500px;
  height: 100%;
  float: left;
}

.title {
  color: white;
  font-size: 30px;
  margin: 0px 5px;
  margin-left: 40px;
  text-align: center;
}

.first {
  padding-top: 30px;
}

html,
body,
.menu {
  height: 100%;
}

body {
  margin: 0;
}

.relative {
  position: relative;
}

li {
  list-style: none;
}

li a {
  display: block;
  text-decoration: none;
  color: white;
  text-align: center;
  font-size: 20px;
}

li a img {
  width: 100%;
  height: 100%;
}

.float-right {
  width: calc(100% - 500px);
  overflow: hidden;
  float: right;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.main-container {
  width: 100%;
  float: left;
}

.header {
  float: left;
  width: 100%;
}

.imgArea {
  float: left;
  width: 75%;
  height: 100%;
}
&#13;
&#13;
&#13;

但现在当我运行我的网站时,它就像 enter image description here

我想首先制作旋转木马,然后显示photo1,然后再显示photo2,再次显示下一张照片......但是现在首先同时显示photo1&amp; photo2,然后再次同时显示它们接下来他们又是......。为什么我的代码错了?我应该怎么解决这个问题?我想把旋转木马放在浏览器剩余的区域和旋转木马的图像大小在该区域调整100%。

2 个答案:

答案 0 :(得分:0)

在bootstrap carousal中,

 <div id="carousel" id="myCarousel" class="carousel slide imgArea 
    float-right" data-ride="carousel">   
    <ul class="carousel-inner">
      <li class="item active">
         <a href="#"><img src="photo1.jpg" alt=""></a>
      </li>
      <li class="item">
         <a href="#"><img src="photo2.jpg" alt=""></a>
      </li> 
    </ul>
 </div>

你可以试试这个

答案 1 :(得分:0)

我不知道为什么你有这么多代码,如果你使用引导程序就可以使用你的转盘,这里有一个简单明了的例子。

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Carousel Example</h2>  
  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner">
      <div class="item active">
        <img src="https://placeimg.com/640/480/arch" alt="Arch" style="width:100%;">
      </div>

      <div class="item">
        <img src="https://placeimg.com/640/480/nature" alt="Nature" style="width:100%;">
      </div>
    
      <div class="item">
        <img src="https://placeimg.com/640/480/tech" alt="Tech" style="width:100%;">
      </div>
    </div>

    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>

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