CSS Transition doesn't work with top, bottom,

2019-01-13 23:50发布

I have an element with style

position: relative;
transition: all 2s ease 0s;

Then I want to change its position smoothly after clicking on it, but when I add the style change the transition doesn't take place, instead the element moves instantly.

$$('.omre')[0].on('click',function(){
    $$(this).style({top:'200px'});
});

However if I change the color property for example, it changes smoothly.

$$('.omre')[0].on('click',function(){
    $$(this).style({color:'red'});
});

What might be the cause of this? Are there properties that aren't 'transitional'?

EDIT: I guess I should have mentioned that this is not jQuery, it's another library. The code appears to work as intended, styles are being added, but transition only works in second case?

2条回答
走好不送
2楼-- · 2019-01-14 00:16

Try setting a default value in the css (to let it know where you want it to start out)

CSS

position: relative;
transition: all 2s ease 0s;
top: 0; /* start out at position 0 */
查看更多
何必那么认真
3楼-- · 2019-01-14 00:33

Perhaps you need to specify a top value in your css rule set, so that it will know what value to animate from.

查看更多
登录 后发表回答