I have a list of posts on a page that when hovered over reveal a overlay that says 'read more'. At the bottom of the page is an button that runs an ajax function to get more posts. After the ajax has successfully loaded the 'read more' thumbnail overlay no longer reveals on mouse over.
This has to be because the javascript has executed already, and I've loaded more elements into the dom. How can I re-execute the same JS function to allow for the new posts to have the overlay as well?
I've tried re-running my function on ajax success, but it didn't seem to do anything. No error or anything.
JavaScript
jQuery(".thumboverlay").mouseenter(function() {
jQuery(this).stop().animate({
opacity: 1
});
});
jQuery(".inspiration-project-title").mouseenter(function() {
jQuery(this).parent(".brick").find(".thumboverlay").stop().animate({
opacity: 1
});
});
jQuery(".thumboverlay").mouseleave(function() {
jQuery(this).stop().animate({
opacity: 0
});
});
jQuery(".inspiration-project-title").mouseleave(function() {
jQuery(this).parent(".brick").find(".thumboverlay").stop().animate({
opacity: 0
});
});
HTML/PHP
<a href='.get_permalink().'>
<div class="inspirations-page-featured-image">
<div class="thumboverlay">
<p>READ MORE</p>
</div>'.$printFeaturedImage.'
</div>
</a>
Ajax
// ajaxLoop.js
jQuery(function($){
var page = 1;
var loading = true;
var $window = $(window);
var $ajaxLoadMoreButton = $("body.blog .ajaxLoadMoreButton");
var $content = $("body.blog #container");
var load_posts = function(){
$.ajax({
type : "GET",
data : {numPosts : 1, pageNumber: page},
dataType : "html",
url : "wp-content/themes/twentytwelve/loopHandler.php",
beforeSend : function() {
if(page !=0) {
$ajaxLoadMoreButton.before('<div id="temp_load" style="text-align:center"><img src="wp-content/themes/twentytwelve/images/ajax-loader.gif" /></div>');
}
},
success : function(data){
$data = $(data);
if($data.length){
$data.hide();
$content.isotope('insert', $(data) );
$data.fadeIn(500, function(){
$("#temp_load").remove();
loading = false;
});
} else {
$("#temp_load").remove();
$ajaxLoadMoreButton.fadeOut().before('<p class="no-more-posts-warning">Sorry, there are currently no more posts to load.</p>');
}
},
error : function(jqXHR, textStatus, errorThrown) {
$("#temp_load").remove();
alert(jqXHR + " :: " + textStatus + " :: " + errorThrown);
}
});
}
$ajaxLoadMoreButton.click(function() {
loading = true;
page++;
load_posts();
});
});