Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Fala galera, estou com uma pequena dúvida. Eu tenho um código certinho para fazer a mudança de um background quando o mouse estiver em ove. Até então tudo bem, mas quero que essa transição seja bem suave, com fade. Podem me ajudar?
Segue abaixo o código (postei aqui com transição em cor, e não imagem.)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
/* ao clicar na div com id="box" executa a função */
$("#box").mouseover(function(){
/* a função muda o background da div com id="box" */
$("#box").css("background","#000");
});
});
</script>
<style type="text/css">
#box {
background: #ccc;
width:300px;
height:200px;
}
</style>
</head>
<body>
<div id="box"></div>
</body>
</html>Então, sou péssimo em JS. Poderia me ajudar a adaptar ao meu código?
http://jsfiddle.net/eric_freitas/kXEm7/7/
tbm não consegui ak só com jquery..
foi preciso também usar o jQueryUI..
http://jqueryui.com/switchClass/#default
<div id="box" class="background-cor1" ></div>
#box {
width:300px;
height:200px;
}
.background-cor1{
background-color: #d1d1d1;
}
.background-cor2{
background-color: #f1f1f1;
}
$("#box").mouseover(function(){
$(this).switchClass( "background-cor1", "background-cor2", 1000 );
});
$("#box").mouseout(function(){
$(this).switchClass( "background-cor2", "background-cor1", 1000 );
});
http://api.jquery.com/animate/
algo tipo
$('.div').animate({ 'background-color': '#333' },500);