【问题标题】:AngularJS multi-item carouselAngularJS 多项目轮播
【发布时间】:2015-07-07 18:24:09
【问题描述】:

我正在使用 UI Bootstrap 轮播,但它只显示一张幻灯片 - http://plnkr.co/edit/Pt56PpQ9fjw6Q0nNF9sU?p=preview
如何以这种方式显示图像?

img1 - img2 - img3
then
img2 - img3 - img4 
then
img3 -img4 - img5
then
img4 - img5 - img6
then
img5 - img6 - img1

(就像在这个轮播中http://coolcarousels.frebsite.nl/c/58/

【问题讨论】:

    标签: javascript angularjs twitter-bootstrap carousel


    【解决方案1】:

    您可以使用 ng-repeat 中的 $index 来创建其他图像并添加接下来的两个图像。

    http://plnkr.co/edit/oVRYCfaMeRW5a54nzmem?p=preview

     <carousel interval="myInterval">
      <slide ng-repeat="slide in slides" active="slide.active">
        <div class="" style="width:600px;margin:auto;">
        <div >
        <img ng-src="{{slide.image}}" width="200px" style="float:left;">
        </div>
        <div >
        <img ng-src="{{slides[getSecondIndex($index+1)].image}}" width="200px" style="float:left;" >
        </div>
         <div >
        <img ng-src="{{slides[getSecondIndex($index+2)].image}}" width="200px" style="float:left;" >
        </div>
        </div>
      </slide>
    </carousel>
    

    获取旋转图像的代码

    $scope.getSecondIndex = function(index)
      {
        if(index-slides.length>=0)
          return index-slides.length;
        else
          return index;
      }
    

    【讨论】:

    • 我已经试过了。问题是 {{slides[$index+1].image}} 和 {{slides[$index+2].image}} 在滑块末尾是空的。例如,如果我在 $scope.slides 中有 4 个图像,它将像这样显示它们:img1 -img2 - img3 然后 img4 - empty - empty。但我希望它显示 img1 - img2 - img3 ,然后是 img4 - img1 - img2,然后是 img1 - img2 - img3 等等。
    • 谢谢,它有效。但它仍然与我想要的有点不同。是否可以让它显示像这个滑块中的图像coolcarousels.frebsite.nl/c/58
    • 卡西尔,非常感谢!我稍微改变了我的滑块,现在一切正常! =))
    • @Kathir 我在角度 2 中遇到问题。您有任何示例。
    • 这个答案不能正常工作。动画是错误的,它做了一个动画,就像它偏移了 3,但它实际上将图像偏移了 1。
    【解决方案2】:

    我正在使用 ng-repeat 并转换为图像,这是我的代码但没有转换

    <carousel interval="myInterval">
        <slide ng-repeat="rc in RequirementConsultanctDetails" active="slide.active">
    
            <div class="" style="width:600px;margin:auto;" ng-show="rc.photo!=null">
                <div>
                    <img ng-src="data:image/jpeg;base64,{{rc.photo}}" width="200px" style="float:left;">               
                </div>
                <div>                 
                    <img ng-src="{{RequirementConsultanctDetails[getSecondIndex($index+1)].photo}}" width="200px" style="float:left;">                  
                </div>
                <div>                 
                    <img ng-src="{{RequirementConsultanctDetails[getSecondIndex($index+2)].photo}}" width="200px" style="float:left;">                   
                </div>
            </div>
        </slide>
    </carousel> 
    

    【讨论】:

    • 这是答案还是问题?
    猜你喜欢
    • 2014-12-02
    • 1970-01-01
    • 2022-01-08
    • 2019-07-11
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    相关资源
    最近更新 更多