Last active
December 29, 2015 17:39
-
-
Save srikat/7705456 to your computer and use it in GitHub Desktop.
Showing Featured images captions on hover in Minimum Pro's Portfolio page. http://sridharkatakam.com/how-to-show-featured-images-captions-on-hover-in-minimum-pros-portfolio-page/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//* Enqueue portfolio image hover script | |
add_action( 'wp_enqueue_scripts', 'portfolio_image_hover_enqueue_script' ); | |
function portfolio_image_hover_enqueue_script() { | |
if ( !is_post_type_archive( 'portfolio' ) ) { | |
return; | |
} | |
wp_enqueue_script( 'portfolio-image-hover', get_bloginfo( 'stylesheet_directory' ) . '/js/portfolio-image-hover.js', array( 'jquery' ), '1.0.0' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Portfolio Image Hover | |
--------------------------------------------- */ | |
.description_overlay { | |
position: relative; | |
} | |
.description { | |
position: absolute; | |
bottom: 0; | |
left: 0; | |
display: none; | |
background-color: #000; | |
font-size: 1em; | |
color: #fff; | |
} | |
.description_content { | |
padding: 20px; | |
padding: 2rem; | |
} | |
@media only screen and (max-width: 1023px) { | |
.post-type-archive-portfolio .entry { | |
text-align: left; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( $image = genesis_get_image( 'format=url&size=portfolio' ) ) { | |
if ( $caption = get_post( get_post_thumbnail_id() )->post_excerpt ) { | |
printf( '<div class="portfolio-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" title="%s" class="overlay" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ), $caption ); | |
} | |
else { | |
printf( '<div class="portfolio-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( $image = genesis_get_image( 'format=url&size=portfolio' ) ) { | |
printf( '<div class="portfolio-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
$(window).load(function() { | |
$("img.overlay").each(function() { | |
//Wrap the image with an overlay | |
$(this).wrap("<div class='description_overlay'></div>"); | |
//Cache description overlay object | |
var o = $(this).parent(".description_overlay"); | |
//Append the description to the overlay | |
o.append("<div class='description'><div class='description_content'></div></div>"); | |
//Align the description with the image | |
o.find(".description").css("opacity", 0); | |
o.find(".description").css("width", $(this).width()); | |
o.find(".description").css("display", "block"); | |
o.find(".description").css("text-align", "center"); | |
//Set the description from the img title attribute | |
o.find(".description_content").html($(this).attr("title")); | |
//Apply the hover effects | |
o.mouseover(function(){ | |
o.find(".description").stop().fadeTo(500, 0.7); | |
}); | |
o.mouseout(function(){ | |
o.find(".description").stop().fadeTo(500, 0); | |
}); | |
}); | |
}); | |
$(window).resize(function() { | |
$("img.overlay").each(function() { | |
//Cache description overlay object | |
var o = $(this).parent(".description_overlay"); | |
o.find(".description").css("width", $(this).width()); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment