2010-09-20 3 views
-3
$(window).load(function() { 
    var paircount = 0; 
    var $thisSprite = $("#%id% img.imageStyle"); 

    if ($.browser.msie) 
    { 
     // I need this only if desaturate png with aplha channel 
     $thisSprite = $thisSprite.desaturateImgFix(); 
    } 

    // modified not to desaturate the clone 
    $thisSprite.each(function(){ 
    $(this).addClass("%id%") 
     .clone() 
     .attr('id', '') 
     .addClass('color') 
     .hide() 
     .insertAfter($(this)) 
    }); 

    // desaturate all occourances 
    $thisSprite = $thisSprite.desaturate(); 

    // Need to remove this instance of the desaturated origonal below on hover 
    // currently shows both on hover...??????????? 
    // add events for switch between color/gray versions 
    $('.centered_image').bind('mouseenter mouseleave', function(e){ 
    $(this).find('img').toggle().toggleClass('color'); 
    }); 

}); 

Новый тест на http://www.doobox.co.uk/test/test.htmlГде добавить jquery "this"?

сердечным приветом
Гэри.

+0

Пожалуйста, добавьте содержимое функции desevent. Я думаю, что это может помочь лучше объяснить, что происходит. – BBonifield

+0

Это похоже на очень неэффективный метод переключения изображений. Вы пытались использовать 'toggleClass' (http://api.jquery.com/toggleClass/) вместо того, чтобы клонировать изображение и скрывать и показывать их? – Mottie

+0

@ BBonifield, добавил полный файл js для просмотра – Doobox

ответ

0

Got там в конце спасибо за указатели здесь, очень помогли.

$(window).load(function() { 


     var paircount = 0; 
     var $thisSprite = $("#%id% img.imageStyle"); 




     if ($.browser.msie) 
     { 
      // I need this only if desaturate png with aplha channel 
      $thisSprite = $thisSprite.desaturateImgFix(); 
     } 

    // modified not to desaturate the clone 
    $thisSprite.each(function(){ 
    $(this).addClass("%id%pair") 
     .clone() 
     .attr('id', '') 
     .insertAfter($(this)) 
     .addClass('%id%color') 
     .hide() 
    }); 

    // desaturate all occourances 
    $thisSprite.desaturate() 


    // Need to remove this instance of the desaturated origonal below on hover 


    // add events for switch between color/gray versions 
    $('.container').bind('mouseenter mouseleave', function(e){ 
    $(this).find('.%id%pair').toggle().toggleClass('%id%color'); 
    }); 

}); 
1

Если вы используете JQuery, то это используется следующим способом -

$('#id',this).hide(); 

Надежда это поможет.

0

Я не вижу петлю, и это только кажется, запутать: (будьте осторожны, если вы Минимизировать здесь)

$thisSprite.addClass("pair%id%_" + ++paircount); 

кажется приравнять:

$thisSprite.addClass("pair%id%_" + 1); 

, который, если вы это:

$thisSprite.addClass("pairsomeIDhere_1"); 

У вас есть такой класс в CSS?

var classString = new String($(this).attr('class')); 

может быть просто:

var classString = $(this).attr('class'); 

изменение:

$thisSprite.bind("mouseenter mouseleave", desevent);  
$cloned.bind("mouseenter mouseleave", desevent);  

передать событие:

$thisSprite.bind("mouseenter mouseleave", desevent(event));  
$cloned.bind("mouseenter mouseleave", desevent(event)); 
+0

Я не могу увидеть, где скрипт origonal зациклился бы над этой строкой, тем самым увеличивая класс: – Doobox

+0

$ thisSprite.addClass («пара% id% _» + ++ paircount); , как вы сказали, не существует петли. Первоначально скрипт вызывался из образа в html. я не могу позвонить из изображения, так как мое изображение представляет собой системную переменную% image% с классом imageStyle, это единственный способ, которым я могу настроить изображение. – Doobox

+0

Я разместил здесь тестовую страницу, чтобы продемонстрировать текущую проблему: http://www.doobox.co.uk/test/test.html – Doobox

0

Глядя на тестовой странице, я думаю, что проблема вам нужно циклически проходить через каждый i маг. Я попытался тестирования, но у меня были проблемы, поэтому, к сожалению, этот сценарий не тестировался:

$(window).load(function() { 

    if ($.browser.msie) 
    { 
     // You need this only if desaturate png with aplha channel 
     $thisSprite = $thisSprite.desaturateImgFix(); 
    } 

    $thisSprite.each(function(){ 
    $(this).clone() 
     .removeAttr('id') 
     .addClass('color') 
     .hide() 
     .insertAfter($(this)) 
     .desaturate(); 
    }); 

    // add events for switch between color/gray versions 
    $('.centered_image').bind('mouseenter mouseleave', function(e){ 
    $(this).find('img, canvas').toggle().toggleClass('color'); 
    }); 
}); 
+0

Я попробую, спасибо, я дам вам знать, как я нахожусь. – Doobox

+0

К сожалению нет: демо с этой поправкой здесь: http://www.doobox.co.uk/stacks_store/demos/doomap.html – Doobox

+0

ps: js можно найти в строке перед тегом закрывающей головки. – Doobox