検索アイコンからローディングにアニメーション遷移
Result
検索アイコンから時計アイコン(ローディング)に遷移する、みたいなやつです
JSというよりCSSがメインになってますが・・
jQuery
$( '.search' ).on( 'click touch' , function (e) {
var self = $( this );
self.addClass( 'loading' );
setTimeout( function () {
self.removeClass( 'loading' );
}, 3000)
});
|
css
.search {
width : 20px ;
height : 20px ;
border : 2px solid #fff ;
border-radius : 50% ;
position : relative ;
margin : 1px 3px 3px 1px ;
cursor : pointer ;
}
.search:before, .search:after {
content : '' ;
display : block ;
position : absolute ;
transform-origin : calc( 100% - 1px ) 50% ;
height : 2px ;
border-radius : 1px ;
background : #fff ;
bottom : calc( 50% - 1px );
right : calc( 50% - 1px );
-webkit- backface-visibility : hidden ;
}
.search:before {
width : 8px ;
transition : transform . 4 s ease;
transform : rotate ( 45 deg) translateX ( 16px );
animation : none ;
}
.search:after {
width : 6px ;
opacity : 0 ;
transform : rotate ( 45 deg);
}
.search.loading:before {
animation : rotate 2.1 s linear forwards . 45 s, move . 3 s linear forwards 2.7 s;
transform : rotate ( 45 deg) translateX ( 0 );
}
.search.loading:after {
opacity : 1 ;
transition : opacity 0 s ease . 4 s;
animation : remove 0 s linear forwards 2.6 s;
}
@keyframes rotate {
100% {
transform : rotate ( 405 deg) translateX ( 0 );
}
}
@keyframes remove {
100% {
opacity : 0 ;
}
}
@keyframes move {
100% {
transform : rotate ( 45 deg) translateX ( 16px );
}
}
|
html
< div class = "search" ></ div >
|
via
Search loading