2010-05-20 18 views
8

ile hover stili Belirli bir öğenin stilini bir stil sayfasında tanımlanan :hover stiline ayarlamak mümkün mü (jQuery kullanarak veya başka bir şekilde)? Daha iyi olurduÖğe stilini şu şekilde ayarla: hoQuery

.regStyle { 
    background-color: #000; 
} 

.regStyle:hover { 
    background-color: #fff; 
} 

Trying it out 

$("#differentButton").click(function(){ 
    // this doesn't work 
    $("#someElement").addClass("regStyle:hover").remove("regStyle"); 
}); 

cevap

3

sayılı sadece CSS o devlete başka bir sınıfa kendisi vermek ve sonra bu sınıf eklemek için yöntemini kullanmak.

.regStyle:hover, 
.regStyle.hover { 
    css: properties; 
    go: here; 
} 

$("#differentButton").click(function(){ 
    // this doesn't work 
    $("#someElement").addClass("hover"); 
}); 
DÜZENLEME: Tamam, onu geri alıyorum. .trigger('mouseover') ile bir yol olabilir. Açıklamak için:
$('.regStyle').mouseover(function() { 
    $(this).css('css','property'); 
}); 

$('.otherElement').click(function() { 
    $('.regStyle').trigger('mouseover'); 
}); 

Tamamen denenmemiş ve biraz daha hantal, ama işe yarayabilir.

+0

de 'mouseOver' mouseover'' olması gerekebilir –

0

Bak http://api.jquery.com/hover/

.hover(handlerInOut) 

    $("li").hover(
     function() { 
     $(this).toggleClass('active'); 
     } 
    ); 


.hover(handlerIn, handlerOut) 

    $("li").hover(
     function() { 
     $(this).addClass('active'); 
     }, function() { 
     $(this).removeClass('active'); 
     } 
    );