I have a page that lists a series of news posts, and each post has multiple images where the URL is placed in the span. Then they are converted to images when you hover over the corresponding message header. I did this due to performance issues with so many images per page.
My problem is that when you hover over the message header, each interval within that particular message is then replaced by the image using only the "first" image URL. So, where was: image-1, image-2, image-3 , then it becomes: image-1, image-1, image-1 .
Do I need to go through the gaps one by one to do this?
I used the following javascript:
$('.article-post').hover(function() {
var elem = $(this).find('span.image');
var src = elem.attr('data-original');
elem.replaceWith('<img src="' + src + '"/>');
});
And here is my HTML layout:
<article class="article-post">
<header class="article-header">
<h1>Title...</h1>
<div class="image-preview">
<ul>
<li>
<span class="image" data-original="http://www..../wp-content/uploads/2016/04/image-1.jpg" >
</li>
<li>
<span class="image" data-original="http://www..../wp-content/uploads/2016/04/image-2.jpg" >
</li>
<li>
<span class="image" data-original="http://www..../wp-content/uploads/2016/04/image-3.jpg" >
</li>
</ul>
</div>
</header>
...
</article>
source
share