Result
検索アイコンから時計アイコン(ローディング)に遷移する、みたいなやつです
JSというよりCSSがメインになってますが・・
jQuery
$('.search').on('click touch', function(e) {
var self = $(this);
self.addClass('loading');//アイコンをクリックしたらladingクラスを付与
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 .4s ease;
transform: rotate(45deg) translateX(16px);
animation: none;
}
.search:after {
width: 6px;
opacity: 0;
transform: rotate(45deg);
}
.search.loading:before {
animation: rotate 2.1s linear forwards .45s, move .3s linear forwards 2.7s;
transform: rotate(45deg) translateX(0);
}
.search.loading:after {
opacity: 1;
transition: opacity 0s ease .4s;
animation: remove 0s linear forwards 2.6s;
}
@keyframes rotate {
100% {
transform: rotate(405deg) translateX(0);
}
}
@keyframes remove {
100% {
opacity: 0;
}
}
@keyframes move {
100% {
transform: rotate(45deg) translateX(16px);
}
}
html
<div class="search"></div>
