简体   繁体   English

为什么过渡对边境财产不起作用?

[英]Why transition doesn't work for border property?

I want to remove border property after a wile (1sec in here) . 我想删除wile之后的border属性(此处为1sec) Also I want to it remove smoothly. 我也想将其顺利移除。 Here is my try: 这是我的尝试:

 var elem = $('div').css({'border-top':'6px solid #FC9A24', 'border-left':'1px dashed #FC9A24', 'margin-top':'-6px'}); setTimeout(function() { elem.css({"transition":"border-color .5s ease"});}, 1000); 
 div{ padding: 10px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <div>Text</div> 

But as you see, border doesn't remove. 但是如您所见, border不会移除。 How can I fix it? 我该如何解决?

Note: similar code for background-color works as well. 注意:类似的background-color代码也可以使用。

The transition goes in parallel with the css attributes, you can't just do transition by itself. 过渡与css属性并行进行,您不能仅仅自己进行过渡。 Here's the way you can get it done. 这是完成任务的方法。

var elem = $('div').css({'border-top':'12px solid green',
                          'border-left':'12px solid blue'});

$('button').click(function() {

setTimeout(function() 
           { 

              elem.css({'border-top':'0px solid green',
                      'border-left':'0px solid blue','transition':'border-top 5s ease, border-top 2s ease'});
           }, 1000);
     });

http://jsfiddle.net/0bm4wq7h/16/ http://jsfiddle.net/0bm4wq7h/16/

 setTimeout(function(){ var elem = document.querySelector('p'); elem.setAttribute('class','styled'); },1000); 
 p { border: 2px solid #f00; transition: all ease-in-out 1s; -moz-transition: all ease-in-out 1s; -webkit-transition: all ease-in-out 1s; } .styled { border: 2px solid #000; } 
 <p>aaaaaaaaaaaaaaaaaaaaaaaaaaa</p> 

Maybe something like this?:) Adding class is much easier. 也许像这样吗?:)添加类要容易得多。 Cheers. 干杯。

That's because border-style is non-animatable. 这是因为border-style不可设置动画。 You can only animate border-color and border-width . 您只能设置border-colorborder-width动画。

 setTimeout(function(){ document.querySelector('p').className = 'no-border'; }, 1e3); 
 p { border: 25px solid #f00; transition: border-width linear 1s; } .no-border { border-width: 0; } 
 <p>aaaaaaaaaaaaaaaaaaaaaaaaaaa</p> 

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

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