views:

132

answers:

4
 $(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');
    });

 });

New test at http://www.doobox.co.uk/test/test.html

Kind regards
Gary.

+1  A: 

If you use JQuery then this is used in following way -

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

Hope this helps you.

Alpesh
A: 

I don't see a loop and this just seems to confuse things:(use caution if you minify here)

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

seems to equate to:

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

which, if you break it down is:

 $thisSprite.addClass("pairsomeIDhere_1");

Do you have such a class in your CSS?

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

can simply be:

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

change:

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

to pass the event:

$thisSprite.bind("mouseenter mouseleave", desevent(event));       
$cloned.bind("mouseenter mouseleave", desevent(event));   
Mark Schultheiss
i cant see where the origonal script would have looped over this line, thus incrementing the class:
Doobox
$thisSprite.addClass("pair%id%_" + ++paircount);like you said there does not appear to be a loop. Originally the script was called from the image in the html. i cant call from the image as my image is a system variable %image% with a class of imageStyle thats the only way i can target the image.
Doobox
I posted a test page here to demonstrate the current problem: http://www.doobox.co.uk/test/test.html
Doobox
A: 

From looking at your test page, I think the problem is you need to cycle through each image. I tried testing this, but I was having trouble, so sadly this script is untested:

$(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');
    });
});
fudgey
i will give that a try, Thank you, i will let you know how i get on.
Doobox
Sadly no: demo with this amendment here: http://www.doobox.co.uk/stacks_store/demos/doomap.html
Doobox
ps: the js can be found in the line before the closing head tag.
Doobox
Hmmm, I'm still not sure why I'm getting a security error when I try to test this, but try modifying the last line to this: `$(this).find('img, canvas').toggle().toggleClass('color');` (edited in the answer above, sorry I forgot the canvas tag was there instead of a second image).
fudgey
All working now, a full demo can be seen here: http://www.doobox.co.uk/stacks_store/demos/sprightly.html ... does not seem to be generating any errors.
Doobox
That's great! :)
fudgey
A: 

Got there in the end thank for the pointers here, helped greatly.

 $(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');
    });

 });
Doobox