Search code examples
jqueryimagehoverswapcaptions

Featured Image on Hover Showing Data for that Image not shown on thumbnails


I need to add dimensions/text data to the featured image on the right. I was going to add it to another image and swap it ... or maybe hide captions with data on the images and show them on the featured? Any thoughts on a best approach for this? Thanks so much for helping me!

http://test.pillarsoflifebook.com/ottomans/

Currently it's just one line of dimensions but I'd like this to be scalable incase the client wants other pages to have a description or more in depth text than a single line.

Thanks so much! Here's the JQuery I'm using for the swap currently:

function myFunction2() {
    var $large = jQuery('#largeImage1');

    //store the default image as the data src
    $large.data('src', $large.attr('src'));

    var src = jQuery('#largeImage').attr('src');
    jQuery('#thumbs1 img').hover(function () {
        $large.attr('src', jQuery(this).attr('src').replace('thumb', 'large'));
    }, function () {
        //on mouse leave put back the original value
        //$large.attr('src', $large.data('src'));
    });
}

jQuery(document).ready(function () {
    jQuery(myFunction2);
});

Solution

  • First use this code for bottommost 4 images (Design options) and tell is it alerting properly the name of items ?

    And hover on 4 bottommost images

    function myFunction() {
        var $large = jQuery('#largeImage');
    
        //store the default image as the data src
        //$large.data('src', $large.attr('src'));
    
        var src = jQuery('#largeImage').attr('src');
    
    
        jQuery('#thumbs img').hover(function () {
            $large.attr('src', jQuery(this).attr('src').replace('thumb', 'large'));
            var altText =jQuery(this).attr("alt");
    
            //alert(jQuery(this).parent().text());
            var existsClass=$large.parent().children().hasClass("prodName");
            //alert(existsClass);
            if(existsClass)
                //$large.parent().children().remove(".prodName");
                $large.parent().find("div").remove(); 
    
    $large.parent().append('<div class="prodName" style="margin-left:220px">'+jQuery(this).parent().text()+'<br/>'+altText+'</div>');
    
        }, function () {
            //on mouse leave put back the original value
            $large.attr('src', $large.data('src'));
        });
    }
    
    jQuery(document).ready(function () {
        jQuery(myFunction);
    });
    

    Check this NEW code