当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - Animate html tab contents to move in/out like carousel using pure css

问题描述:

I am new to animations. I have a simple html tab, i would like to slide the contents move like a carousel, something like this http://css3.bradshawenterprises.com/sliding/ using CSS.

Any pointers on how to do this will be helpful.

<div class="service-tabs" >

<ul class="nav nav-tabs">

<li ng-class="{'active':tabSelected == 'one'}" ng-click="tabSelected = 'one'">TAB ONE</li>

<li ng-class="{'active':tabSelected == 'two'}" ng-click="tabSelected = 'two'">TAB TWO</li>

<li ng-class="{'active':tabSelected == 'three'}" ng-click="tabSelected = 'three'">TAB THREE</li>

</ul>

<div class="tab-contents">

<div class="tab-content" ng-show="tabSelected == 'one'" ng-class=" tabSelected == 'one' ? 'active' : 'inactive'">

<div class="flex-it risk-factors">

<h1>One</h1>

<p>Lorem dim sum Cha siu bao Lo mai gai baked barbecue pork bao Egg custard tarts Popular shumai cha siu bao A creamy mango pudding Chiu-chao</p>

</div>

</div>

<div class="tab-content" ng-show="tabSelected == 'two'" ng-class=" tabSelected == 'two' ? 'active' : 'inactive' " style="width: 100%">

<h1>Two</h1>

<p>Bacon ipsum dolor amet beef ham hock salami cupim shankle kevin leberkas landjaeger ham. Prosciutto filet mignon bresaola rump. Tail ground round beef tri-tip turducken, meatloaf prosciutto short ribs filet mignon t-bone hamburger kevin pork chop. Meatball rump chicken hamburger drumstick, boudin pancetta short ribs ground round. Turkey cupim porchetta salami sausage t-bone pig. Bresaola t-bone tenderloin pork shoulder. Tongue pig corned beef, ball tip ham hock swine alcatra jowl pork strip steak sirloin flank leberkas.</p>

</div>

<div class="tab-content" ng-show="tabSelected == 'three'" ng-class=" tabSelected == 'three' ? 'active' : 'inactive' ">

<h1>Three</h1>

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

</div>

</div>

</div>

Here is the plunker i have so far

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

网友答案:

OK, so here's one way of doing it. The main trick here is setting the default transition-delay on the content elements to something ridiculously high so that they can never "snap back" to their original position without the user interacting with one of the tabs, resetting that delay to 0 when a tab gains focus. Apart from that, it's all just basics: sibling selectors, transitions & positioning.

*{box-sizing:border-box;color:#000;font-family:sans-serif;font-size:14px;margin:0;outline:none;padding:0;}
body{
    margin:10px;
}
body>p{
    cursor:pointer;
    line-height:30px;
    padding:0 20px;
    display:inline-block;
}
body>p:focus{
    background:#ccc;
}
body>div{
    border:2px solid #ccc;
    overflow:hidden;
    white-space:nowrap;
    width:100%;
}
div>div{
    display:inline-block;
    left:0;
    padding:10px;
    position:relative;
    transition:left .5s linear 9999s;
    white-space:initial;
    width:calc(100% - 4px);
}
#tab1:focus~div>div{
    left:0%;
    transition-delay:0s;
}
#tab2:focus~div>div{
    left:-100%;
    transition-delay:0s;
}
#tab3:focus~div>div{
    left:-200%;
    transition-delay:0s;
}
h1{margin:0 0 10px;}
<p id="tab1" tabindex="-1">Tab 1</p>
<p id="tab2" tabindex="-1">Tab 2</p>
<p id="tab3" tabindex="-1">Tab 3</p>
<div>
    <div>
        <h1>Page One</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non libero libero. Etiam a dui scelerisque, cursus ex non, dapibus nibh. Donec ac venenatis ligula. Curabitur mollis libero a elit tempus pretium. Ut ultricies viverra mollis. In efficitur purus at cursus pulvinar. Ut condimentum metus at ante viverra porttitor. Nullam vel purus mi. Nunc vel suscipit sapien, id faucibus sem. Sed tristique laoreet purus commodo molestie. Nulla volutpat feugiat enim at volutpat. Fusce dictum augue felis, sit amet sodales ipsum ultricies sed. Quisque molestie neque at lacus euismod, nec pharetra tellus vulputate. Fusce ut ante tellus. Curabitur lacinia gravida mauris sed pharetra.</p>
    </div>
    <div>
        <h1>Page Two</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non libero libero. Etiam a dui scelerisque, cursus ex non, dapibus nibh. Donec ac venenatis ligula. Curabitur mollis libero a elit tempus pretium. Ut ultricies viverra mollis. In efficitur purus at cursus pulvinar. Ut condimentum metus at ante viverra porttitor. Nullam vel purus mi. Nunc vel suscipit sapien, id faucibus sem. Sed tristique laoreet purus commodo molestie. Nulla volutpat feugiat enim at volutpat. Fusce dictum augue felis, sit amet sodales ipsum ultricies sed. Quisque molestie neque at lacus euismod, nec pharetra tellus vulputate. Fusce ut ante tellus. Curabitur lacinia gravida mauris sed pharetra.</p>
    </div>
    <div>
        <h1>Page Three</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non libero libero. Etiam a dui scelerisque, cursus ex non, dapibus nibh. Donec ac venenatis ligula. Curabitur mollis libero a elit tempus pretium. Ut ultricies viverra mollis. In efficitur purus at cursus pulvinar. Ut condimentum metus at ante viverra porttitor. Nullam vel purus mi. Nunc vel suscipit sapien, id faucibus sem. Sed tristique laoreet purus commodo molestie. Nulla volutpat feugiat enim at volutpat. Fusce dictum augue felis, sit amet sodales ipsum ultricies sed. Quisque molestie neque at lacus euismod, nec pharetra tellus vulputate. Fusce ut ante tellus. Curabitur lacinia gravida mauris sed pharetra.</p>
    </div>
</div>
分享给朋友:
您可能感兴趣的文章:
随机阅读: