简体   繁体   English

在图像切换之间添加CSS过渡

[英]Add CSS Transition between image switch

In my site I have a switch between a down arrow & and an up arrow. 在我的网站上,我可以在向下箭头&和向上箭头之间进行切换。 See here 这里

How do I change this to a CSS transition, so there's a brief break between the switch? 如何将其更改为CSS过渡,因此在切换之间有短暂的中断?

Here's my code: 这是我的代码:

 function close_accordion_section(source) { $(source).parent().find('.accordion-section-title').removeClass('active'); $(source).parent().find('.accordion-section-content').slideUp(300).removeClass('open'); } $('.accordion-section-title').click(function (e) { if ($(e.target).is('.active')) { close_accordion_section(e.target); } else { $(this).addClass('active'); $(e.target).parent().find('.accordion-section-content').slideDown(300).addClass('open') } e.preventDefault(); }); 
 .accordion { overflow: hidden; margin-bottom: 40px; } .accordion-section { padding: 15px; border: 1px solid #d8d8d8; background: #fbfbfb; } .accordion-section-title { width: 100%; display: inline-block; background-image: url("https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_keyboard_arrow_up_48px-512.png"); background-size: 5% 100%; background-repeat: no-repeat; background-position: top right; } .accordion-section-title.active { background: url("https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_keyboard_arrow_down_48px-128.png") top right no-repeat; background-size: 5% 100%; background-repeat: no-repeat; } .accordion-section-title.active, .accordion-section-title:hover { text-decoration: none; transition: color 0.1s linear; } .accordion-section-content { padding: 15px 0; display: none; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="accordion"> <div class="accordion-section"> <a class="accordion-section-title" href="#accordion-1">More information</a> <div id="accordion-1" class="accordion-section-content"> <p>Text.</p> <p> </div> </div> </div> 

You can do this in 2 ways that I can think of. 您可以通过两种我可以想到的方式来做到这一点。 One is by jQuery-UI and add a 一个是通过jQuery-UI并添加一个

.delay(2000) 

to the end of your transition. 到过渡结束 The other way is in your css class for your transition is do a 另一种方法是在您的CSS类中进行转换

transition-delay: 2s;

For the arrow, it would be better to transition and rotate the image. 对于箭头,最好过渡和旋转图像。

.rotate{
    -ms-transform: rotate(180deg); /* IE 9 */
    -webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
    transform: rotate(180deg);
}

Here is a neat website to help you with that: http://www.css3maker.com/css3-transition.html 这是一个简洁的网站,可为您提供帮助: http : //www.css3maker.com/css3-transition.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM