jQuery로 간단한 너비 및 배경 색상 애니메이션을 처리하려고합니다 (apple.com의 검색 상자와 비슷 함).jQuery로 색상에 애니메이션 적용하기 단계 함수 및 CSS rgb()
기본적으로 양식 필드에 중점을두고 그 부모가 배경색을 변경하고 넓어지면 흐림 효과에서 부모의 너비와 배경색이 다시 변경됩니다.
jQuery Color 플러그인을로드하지 않으려 고합니다. 그래서 간단한 해결 방법을 찾았습니다. 문제는 배경색이 초점을 맞춰 완벽하게 움직이지만 아무 것도 흐려지지 않습니다. 어떤 도움이라도 대단히 감사하겠습니다. 여기
내 코드입니다 : (시작 배경색이rgb(243, 243, 243)
당신이 궁금해하는 경우 그 숫자가 어디에서 오는지)
$('#s').focus(function() {
$('#header-search-form').animate(
{'width': '175px'}, {
duration : 150,
easing : 'swing',
step : function(now, fx) {
var completion = (now - fx.start)/(fx.end - fx.start);
$('#header-search-form').css('backgroundColor', 'rgb(' + 243+(255-243)*completion + ',' + 243+(255-243)*completion + ',' + 243+(255-243)*completion + ')');
}
});
});
$('#s').blur(function() {
$('#header-search-form').animate(
{'width': '125px'}, {
duration : 150,
easing : 'swing',
step : function(now, fx) {
var completion = (now - fx.start)/(fx.end - fx.start);
$('#header-search-form').css('backgroundColor', 'rgb(' + 255-(255-243)*completion + ',' + 255-(255-243)*completion + ',' + 255-(255-243)*completion + ')');
}
});
});
경우는, 내가 색상을 애니메이션에 대한 간단한 jQuery 플러그인을 만들려면 여기를 배운 것을 적용했다. 여기에서 확인할 수 있습니다 : https://gist.github.com/dominic-p/4569265 –