views:

37

answers:

2

I need to get this code to work so when the item is clicked the mouseout doesn't fade out the element.

$('.link1').hover(function(){
    $('#image1').fadeIn();
},function(){
    $('#image1').fadeOut();
}).click(function(){
    $('#image1').css('display','block');
});

Thanks in advance.

A: 

Add some attribute so you can check on it.

$('.link1').hover(function(){
  if(!$('#image1').is(':visible')) $('#image1').fadeIn();
}, function(){
  if(!$(this).attr("clicked")) $('#image1').fadeOut();
}).click(function(){
  $(this).attr("clicked", true);
  $('#image1').css('display','block');
});
Anpher
+4  A: 
$('.link1').hover(function(){
    $('#image1').fadeIn();
},function(){
    var clicked = $(this).data('clicked');
    if(!clicked) $('#image1').fadeOut();
}).click(function(){
    $(this).data('clicked', true);
    $('#image1').css('display','block');
});
sje397
I now need to dynamically add the id of image and this doens't seem to work. I've just tried to get the first part to work. $('#image-map area').hover(function(){ var linkClass = $(this).attr("class"); var linkClassID = '#' + linkClass; linkClassID.stop(true, true).fadeIn(); },function(){ var clicked = $(this).data('clicked'); if(!clicked) $('#image1').stop(true, true).fadeOut(); }).click(function(){ $(this).data('clicked', true); $('#image1').css('display','block'); $('#image1').siblings('display','none'); });
Model Reject
@Clint - that's a bit hard to read. Perhaps it deserves a separate question?
sje397