Hi all,
Couple of questions, and thanks in advance
First problem
When I click a read-more
link, a hidden container will appear - works good. Now if I close this container using the close link within, it will hide again, works good. The problem is, when I resize the window, and sometimes when I scroll on mobile the hidden div container will reappear.
Question
If the container is hidden, why does it reappear when I resize the window?
I think it has something to do with the display: none and display: inline-block ordering, can’t figure out what I’ve missed.
Everything can be seen and tested in my Codepen example for easy viewing.
var $chosen = null;
$(window).on('resize', function() {
if ($chosen != null) {
$content.css('display','none');
$('body').append($('#content'));
$chosen.trigger('click');
}
});
//Display extra #content container
$(document).on('click', '#results .read-more', function(e){
e.preventDefault();
$chosen = $(this);
var position = $chosen.closest('.wrapblock').position();
$content.css('display','inline-block');
$('.wrapblock').filter(function(idx, ele){
return $(ele).position().top == position.top;
})
.last()
.after($content);
});
// Close #content conatiner
$(document).on('click', '.close-me', function(e){
$(this).closest($content).hide();
e.preventDefault();
});
Second problem
After closing the extra container as discussed above, if I select another read more link the container reappears in the same place it was closed. Its only after the second click that the extra container moves into position.
Question
Why does the container not move into the correct position on first click?
Hopes this makes sense, codepen shows all code and problems.
And thanks to @m3g4p0p on an older thread as this is related.
Cheers,
Barry