CSS3实现div从下往上滑入滑出效果示例

发布时间:2022-04-13 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了CSS3实现div从下往上滑入滑出效果示例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

1,首先需要用的是 CSS3的 target 选择器,配合a标签指定id选择器切换目标元素,用于选取当前活动的目标元素。
2,CSS3 的 transITion 动画,这里不做详细介绍

看一下效果图:

点击滑出按钮,元素从底部匀速滑入到页面一定高度;再点击滑入,元素从当前位置匀速滑入期初位置。


直接上代码:

<h1>CSS3滑入/滑出效果</h1>
<div id="volet_clos">
    <div id="volet">
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima quisquam tempora quaerat dolores molestias reiciendis .</p>
        <p>vero labore voluptates necessitatibus ut? Et</p>
        <p>vero labore voluptates necessitatibus ut? Et</p>
        <p>vero labore voluptates necessitatibus ut? Et</p>
        <p>vero labore voluptates necessitatibus ut? Et</p>

        <a href="#volet"  aria-hidden="true" class="ouvrir">滑出</a>
        <a href="#volet_clos" aria-hidden="true" class="fermer">滑入</a>
    </div>
</div>
 <style>
        #volet_clos {position: fixed;top: 0px; left: 0;width: 100%;}
        #volet {width: 250px;padding: 10px;background: #6B9A49; color: #fff;width: 100%;}
        /* 初始定位 */
        #volet {position: absolute;left: 0px;top: 375px;transition: all .5s ease-in;}   
        #volet a.ouvrir,#volet a.fermer {position: absolute;right: -88px;top: 150px;}
        /* 点击过后改变 target  */
        #volet a.fermer {display: none;}
        #volet:target {left: 0px;top: 150px;}
        #volet:target a.fermer {display: block;}
        #volet:target a.ouvrir {display: none;}
        #volet_clos:target #volet {left: 0px;top: 375px;}
        #volet a.ouvrir,#volet a.fermer{position: absolute;right: calc(40%);top: -40px;padding: 10px 25px; background: #555; color: #fff; text-decoration: none;text-align: center; width: 120px;}
    </style>

案例二,tab标签页切换效果

&nbsp;
 

 
 

<h1>tab标签页切换效果</h1>
<div class="swiPEr-box">
    <div class="swiper-cont">
        <div class="swiper1" id="swiper1"></div>
        <div class="swiper2" id="swiper2"></div>
        <div class="swiper3" id="swiper3"></div>
    </div>
    <div class="swiper-num">
        <a href="#swiper1">1</a>
        <a href="#swiper2">2</a>
        <a href="#swiper3">3</a>
    </div>
</div>
/* tab标签页切换效果 css */
.swiper-box{position: relative;width: 500px; height: 300px; margin: 20px auto; background: #F1f1f1;}
.swiper-cont div,.swiper1,.swiper2,.swiper3{ width: 0%; height: 300px;position: absolute;top: 0; left: 0;transition: width .5s linear;}
.swiper1{background: linear-gradient(to top, #fba555, #ffed6c 75%);}
.swiper2{background: linear-gradient(to left, #55d5fb, #fd74a7 75%);}
.swiper3{background: linear-gradient(to top left, #55fb69, #6CFff1  75%);}
.swiper-num{position: absolute; bottom: 0;right: 0;display: inline-block;z-index: 9;}
.swiper-num a{display: inline-block;margin-left: 10px;padding: 10px 20px; color: #333;font-Size: 14px; text-decoration: none;font-weight: bold;background: rgba(255,255,255,.45);}
.swiper-num a:hover,.swiper-num a:active{ color: red;cursor: pointer;background: rgba(255,255,255,.95);}
.swiper-box :target{width: 100%;transition: width .5s linear;}

到此这篇关于CSS3实现div从下往上滑入滑出效果示例的文章就介绍到这了,更多相关CSS3实现div从下往上滑入滑出内容请搜索脚本宝典以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本宝典!

脚本宝典总结

以上是脚本宝典为你收集整理的CSS3实现div从下往上滑入滑出效果示例全部内容,希望文章能够帮你解决CSS3实现div从下往上滑入滑出效果示例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:CSS3div