I have simple toggle div. I need on the big screens paragraph content open when hover, and on the small screens when click. I try to do like this:
HTML:
<div class="container">
<div class="headline">Headline exaple</div>
<p class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae quia nulla, rem harum, minima sint assumenda perferendis cupiditate rerum corporis obcaecati, quam natus repudiandae veniam dolor. Maiores commodi sequi, esse.
</p>
</div>
CSS:
.container {
width: 400px;
border: 1px solid #ccc;
border-radius: 5px;
}
.headline {
background: #ccc;
padding: 5px;
cursor: pointer;
}
.headline:hover + .content {
display: block;
}
.content {
padding: 5px;
display: none;
}
jQuery:
var isSmallWindow;
$(window).on('resize', function() {
isSmallWindow = $(this).width() < 768;
});
$('.headline').on('click', function() {
if (isSmallWindow) {
$('.content').slideToggle(300);
}
});
But it does not work properly. When I change the window size content is still open when hover. I clicked on the headline and when I return window of its original position, then hover not working. How to solves this problem?