I'm working on a WordPress website and my blog posts are set up like this:
When I click on an arrow on either side, the current set of six posts fade out and the new set of posts fade in using the code below:
$('#article-list').on('click', '.paging-navigation a', function(e){
e.preventDefault();
var link = $(this).attr('href');
$('#article-list').fadeOut(500, function(){
$(this).load(link + ' #article-list', function() {
$(this).fadeIn(500);
});
});
});
I also have it set up so that when I hover over a post thumbnail, the image fades out and the text fades in using the code below:
$('article').on("mouseenter mouseleave", function( e ) {
// mouseenter variable returns true if mouseenter event is occurring
// and it returns false if event is anything but mouseenter.
var mouseenter = e.type === "mouseenter",
$this = $(this),
img = $this.children('img'),
postInfo = $this.children('.post-info');
// Both of these use ternary if statements that are equal to:
// if ( mouseenter ) { var imgFade = 0.4; } else { var imgFade = 1; }
// if ( mouseenter ) { var postInfoFade = 'fadeIn'; } else { var postInfoFade = 'fadeOut'; }
var imgFade = mouseenter ? 0.4 : 1,
postInfoFade = mouseenter ? 'fadeIn' : 'fadeOut';
img.stop().fadeTo( 500, imgFade );
postInfo.stop()[ postInfoFade ]( 500 );
});
This is my HTML:
<div id="article-list">
<article>
<div class="post-info" style="display: none; opacity: 1;">
<h1 class="entry-title"><a href="/" rel="bookmark">Post Title</a></h1>
<span class="posted-on">
<a href="/" rel="bookmark">
<time class="entry-date published" datetime="2014-09-04T06:35:12+00:00">September 4, 2014</time>
<time class="updated" datetime="2014-09-05T01:59:18+00:00">September 5, 2014</time>
</a>
</span>
</div>
<img width="312" height="200" src="post-image.jpg" style="opacity: 1;">
</article>
<article>
<div class="post-info" style="display: none; opacity: 1;">
<h1 class="entry-title"><a href="/" rel="bookmark">Post Title</a></h1>
<span class="posted-on">
<a href="/" rel="bookmark">
<time class="entry-date published" datetime="2014-09-04T06:35:12+00:00">September 4, 2014</time>
<time class="updated" datetime="2014-09-05T01:59:18+00:00">September 5, 2014</time>
</a>
</span>
</div>
<img width="312" height="200" src="post-image.jpg" style="opacity: 1;">
</article>
<article>
<div class="post-info" style="display: none; opacity: 1;">
<h1 class="entry-title"><a href="/" rel="bookmark">Post Title</a></h1>
<span class="posted-on">
<a href="/" rel="bookmark">
<time class="entry-date published" datetime="2014-09-04T06:35:12+00:00">September 4, 2014</time>
<time class="updated" datetime="2014-09-05T01:59:18+00:00">September 5, 2014</time>
</a>
</span>
</div>
<img width="312" height="200" src="post-image.jpg" style="opacity: 1;">
</article>
<article>
<div class="post-info" style="display: none; opacity: 1;">
<h1 class="entry-title"><a href="/" rel="bookmark">Post Title</a></h1>
<span class="posted-on">
<a href="/" rel="bookmark">
<time class="entry-date published" datetime="2014-09-04T06:35:12+00:00">September 4, 2014</time>
<time class="updated" datetime="2014-09-05T01:59:18+00:00">September 5, 2014</time>
</a>
</span>
</div>
<img width="312" height="200" src="post-image.jpg" style="opacity: 1;">
</article>
<article>
<div class="post-info" style="display: none; opacity: 1;">
<h1 class="entry-title"><a href="/" rel="bookmark">Post Title</a></h1>
<span class="posted-on">
<a href="/" rel="bookmark">
<time class="entry-date published" datetime="2014-09-04T06:35:12+00:00">September 4, 2014</time>
<time class="updated" datetime="2014-09-05T01:59:18+00:00">September 5, 2014</time>
</a>
</span>
</div>
<img width="312" height="200" src="post-image.jpg" style="opacity: 1;">
</article>
<article>
<div class="post-info" style="display: none; opacity: 1;">
<h1 class="entry-title"><a href="/" rel="bookmark">Post Title</a></h1>
<span class="posted-on">
<a href="/" rel="bookmark">
<time class="entry-date published" datetime="2014-09-04T06:35:12+00:00">September 4, 2014</time>
<time class="updated" datetime="2014-09-05T01:59:18+00:00">September 5, 2014</time>
</a>
</span>
</div>
<img width="312" height="200" src="post-image.jpg" style="opacity: 1;">
</article>
<nav class="navigation paging-navigation" role="navigation">
<h1 class="screen-reader-text">Posts navigation</h1>
<div class="nav-links">
<div class="nav-previous">
<a href="/page/2/">
Older posts <span class="meta-nav">→</span>
</a>
</div>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
</div><!-- #article-list -->
My problem:
When I click an arrow to reveal the next set of posts, two things go wrong:
1) The mouse hovers stop working, meaning that when I hover over a post thumbnail, nothing happens.
2) The new set of posts get wrapped in their own #article-list
div so there ends up being two #article-list
divs with one parenting the other.
Here's what I mean:
I'm having a hard time trying to get these two issues fixed. If anybody out there can identify the problem, I'd really appreciate the help!