Using hover to swap images, I don't want to swap images if I'm on '.this_page'...

Posted by richoid on Stack Overflow See other posts from Stack Overflow or by richoid
Published on 2010-03-19T06:08:20Z Indexed on 2010/03/19 6:11 UTC
Read the original article Hit count: 224

Filed under:
|
|
|
|

When I land on the page, another function (not shown, that works fine) sets the class of the appropriate nav to '.this_page' and then I roll over, and the images swap correctly, but when I hover and leave 'img.this_page' it swaps, the second time I do the hover. I don't want it 'img.this_page' to swap. I tried unbinding mouseout, but on hover apparently it rebinds... so each time you hover, it resets.

Page is at http://flourgarden.com/wp/

Here's my function:

function hoverNavs() {
            var baseURL='http://www.flourgarden.com/wp/wp-content/themes/flourgarden/images/nav';
            var cache=[];

            $j('.lcolumn a img').each(function() {

                var t = $j(this);
                var src1 = t.attr('src'); // initial src
                var newSrc = src1.substring(src1.lastIndexOf('/'), src1.lastIndexOf('.')); // let's get file name without extension

                i = baseURL+newSrc+'_select.png';
                cache.push(i);

                t.hover(function(){
                    $j(this).attr('src', baseURL+newSrc+ '_select.' + /[^.]+$/.exec(src1)); //last part is for extension       
                }, function(){
                    if($j(this).class == "this_page") {
                        $j(this).attr('src', baseURL+newSrc+ '_select.' + /[^.]+$/.exec(src1));
                    } else {
                        $j(this).attr('src', baseURL+newSrc+ '.' + /[^.]+$/.exec(src1));
                    }
                });
            });
        }

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about bind