加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS图像滑块

发布时间:2020-12-17 17:37:45 所属栏目:安全 来源:网络整理
导读:我正在使用来自 here的代码使用Angularjs创建一个图像滑块 使用AngularJS 1.15,我可以让图像滑入.但是当第二张图像进入时,第一张图像将消失而不是滑出.有人可以帮忙吗? 注意:这不适用于Firefox和IE,但适用于Chrome. 这是我的代码 HTML div ng-controller="
我正在使用来自 here的代码使用Angularjs创建一个图像滑块

使用AngularJS 1.15,我可以让图像滑入.但是当第二张图像进入时,第一张图像将消失而不是滑出.有人可以帮忙吗?

注意:这不适用于Firefox和IE,但适用于Chrome.

这是我的代码
HTML

<div ng-controller="slideShowController" class="imageslide" ng-switch='slideshow' ng-animate="'animate'">
    <div class="slider-content" ng-switch-when="1">
        <img src="asset/building.jpg" width="100%" height="400px"/>
    </div>  
<div class="slider-content" ng-switch-when="2">
    <img src="asset/slide-2.jpg" width="100%" height="400px"/>
    </div>
<div class="slider-content" ng-switch-when="3">
    <img src="asset/slide-3.jpg" width="100%" height="400px"/>
    </div>  
<div class="slider-content" ng-switch-when="4">
    <img src="asset/slide-4.jpg" width="100%" height="400px"/>
    </div>  
    </div>

使用Javascript

function slideShowController($scope,$timeout) {
 var slidesInSlideshow = 4;
 var slidesTimeIntervalInMs = 3000; 

 $scope.slideshow = 1;
 var slideTimer =
 $timeout(function interval() {
     $scope.slideshow = ($scope.slideshow % slidesInSlideshow) + 1;
     slideTimer = $timeout(interval,slidesTimeIntervalInMs);
     },slidesTimeIntervalInMs);
 }

CSS

.imageslide{
width:100%;
height:400px;
margin: 0 auto;
margin-bottom: 20px;
}

.imageslide .slider-content {
position: absolute;
width:100%;
height:400px;
}

.animate-enter,.animate-leave {
-webkit-transition:1000ms cubic-bezier(.165,.84,.44,1) all;
-moz-transition:1000ms cubic-bezier(.165,1) all;
-ms-transition:1000ms cubic-bezier(.165,1) all;
-o-transition:1000ms cubic-bezier(.165,1) all;
transition:1000ms cubic-bezier(.165,1) all;
}

.animate-enter {
left:100%;
}

.animate-leave.animate-leave-active {
left:-100%;
}

.animate-enter.animate-enter-active,.animate-leave {
left:0;
}

解决方法

我看到你的plunker最大的问题是页面上缺少ng-app属性.添加并将动画更改为使用margin-left后,它可以正常工作:

.animate-leave.animate-leave-active {
    margin-left:-100%;
}

叉形弹药:
http://plnkr.co/edit/BxWNlYVJUCNL7C1K65aU?p=preview

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读