2012-12-02 5 views
2

현재 모든 사람들이 두 솔루션의 이야기 :jQuery를 사용하여 배경색을 희미하게 만드는 방법은 무엇입니까?

  1. jQuery를 UI 플러그인 -> 가능하지를, 너무 많은 공간
  2. 를 사용하기 때문에
  3. jQuery를 컬러 (http://api.jquery.com/animate/) - -> 실제로 다운로드 할 플러그인에 대한 링크를 얻을 수 없기 때문에 가능하지 않습니다.

제 질문은 jQuery v1.7.2에서이 효과를 허용하는 데 사용할 수있는 가장 작은 플러그인은 무엇입니까?

+0

방금 ​​페이드 인하거나 아웃하거나, 플러그인이 필요하거나 animate() 단계 방법에 연결하는 두 가지 색상이 희미 해지고 있습니까? – adeneo

+0

나는 퇴색하고 있습니다. 녹색은 3 초 만에 투명하게 나타 납니까? – coderama

+1

투명성으로 변색하는 것은 불투명도로 요소를 사라지게하는 것과 같습니다. 이는 플러그인을 전혀 필요로하지 않습니다. -> [** FIDDLE ** 참조] (http://jsfiddle.net/784Wb/) – adeneo

답변

3

jQuery Color 플러그인을 GitHub 저장소에서 가져올 수 있습니다.

$("span.value").animate({ 
    backgroundColor: "transparent" 
}, 'slow'); 

See a live example using jQuery Color.


또한 CSS3 transitions를 사용할 수있다

span.value { 
    background-color: #0f0; 
} 
. ,

span.value { 
    background-color: #0f0; 
    -o-transition-duration: 0.8s; 
    -moz-transition-duration: 0.8s; 
    -ms-transition-duration: 0.8s; 
    -webkit-transition-duration: 0.8s; 
    transition-duration: 0.8s; 
} 

.fade { 
    background-color: transparent; 
} 

$("span.value").toggleClass("fade"); 

See a live example using CSS· transitions.

+0

$ ("span.value"). animate ({backgroundColor : '# 00FF00'}) -> 이것은 한쪽에서 다른쪽으로 희미 해지지 만 오히려 색을 바꿉니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? – coderama

+0

@RD., 어떤 컨텍스트없이 알 수있는 방법은 없습니다. 방금 게시 한 예제를 확인할 수 있습니다 – Alexander

+1

속도 ->'$ ("span.value") 애니메이션이 없습니다 ({backgroundColor : '# 00FF00'}, 3000), ' – adeneo

0

나는하지 마십시오하지만, ou는 어쩌면 RGBA로

RGBA (0, 255, 0, 1) => RGBA (0 애니메이션을 적용 할 수 있습니다 255, 0, 0)

+0

아니, 그럴 수 없어 !!! – adeneo

+1

어쩌면 쿼리가 아니라 setTimeout – Ajouve

0

시도해보십시오. 시도해보십시오.

,210
$('span').animate({'backgroundColor' : '#ffff99'}); 

또는 궁극적으로 jQuery를 색상 플러그인을 사용하지 않을 경우는, CSS 전환 사용할 수

$("span").fadeOut("slow").css("background-color", "#ffff99"); 
+1

jQuery UI가 없어도 될까요? – adeneo

2

시도 :

<button id="fadeTrigger">fade with jQuery <span>(and CSS...)</span></button> 

<div id="target" class="base"> 
    <p>some text in the targetted div element</p> 
</div>​ 

그리고 jQuery를 :

$('#fadeTrigger').click(
    function(){ 
     $('#target').toggleClass('base highlighted'); 
    });​ 

및 CSS :

button { 
    font-size: 1em; 
} 

button span { 
    font-size: 0.6em; 
    font-style: italic; 
} 

#target.base { 
    background-color: #fff; 
    -moz-transition: all 1s linear; 
    -ms-transition: all 1s linear; 
    -o-transition: all 1s linear; 
    -webkit-transition: all 1s linear; 
    transition: all 1s linear; 
} 

#target.highlighted { 
    background-color: #f90; 
    -moz-transition: all 1s linear; 
    -ms-transition: all 1s linear; 
    -o-transition: all 1s linear; 
    -webkit-transition: all 1s linear; 
    transition: all 1s linear; 
} 

JS Fiddle demo.

0

당신은 오히려 그들을 다운로드하는 것보다 당신의 head 태그

<script type="text/javascript" src=""></script> 

와 그 플러그인을 사용할 수 있습니다.

당신은 호버에 CSS에서 opacity 속성을 사용할 수

$(this).animate({ backgroundColor: '#HEXCODE' }, 'fast'); 

을 시도하거나.

#id{ 
    opacity:1; 
    } 

#id:hover{ 
    opacity: 0.8; 
} 
+0

나는 그것이 어떻게 작동하는지 당신이 정말로 이해한다고 생각하지 않는다. 사용자는 자신의 서버 또는 다른 사람의 서버에 링크되어 있는지에 관계없이 스크립트를 다운로드해야합니다. – adeneo

+0

나는 사용자가 다운로드하지 않는다고 말하지 않았다. 나는 @RD를 말했다. 자신의 서버에서 다운로드하고 링크 할 필요가 없습니다. – nerdarama

0

색상을 희미하게 만드는 아주 간단한 jQuery 플러그인을 작성했습니다. 그것은 약간의 연마를 사용할 수 있지만, 나는 그것이 당신이 무엇인지 생각합니다. 당신은 여기에서 그것을 확인할 수 있습니다 : https://gist.github.com/4569265

관련 문제