can someone help me fix this problem ? I just learn CSS and Js so I dont really know what to do.
this thing going up and down 2x before showing the content, then going up and down again before hide the content.
CSS:
.pureyad {
max-width: 600px;
line-height: 1.1em;
font-family: 'Roboto Slab';
overflow: hidden;
background: #46988f;
font-size: 14px;
height: 120px;
padding-left: 20px
}
.purgex {
display: block;
background: transparent;
border: none;
border-top: 1px solid #222;
width: 585px;
max-width: 100%;
font-family: 'baloo bhai';
font-size: 15px
}
JS:
function ssss() {
var text = $('.pureyad'),
btn = $('.purgex'),
h = text[0].scrollHeight;
if(h > 120) {
btn.addClass('less');
}
btn.click(function(e)
{
e.stopPropagation();
if (btn.hasClass('less')) {
btn.removeClass('less');
btn.addClass('more');
btn.text('Show less');
text.animate({'height': h});
} else {
btn.addClass('less');
btn.removeClass('more');
btn.text('Show more');
text.animate({'height': '120px'});
}
});
}
HTML :
<div class="pureyad">
<p>Lorem ipsum dolor sit amet..</p>
</div>
<center><button class="purgex" onclick="ssss()">Show more</button></center>
Gif up and down: http://i.giphy.com/l0HlJmVHLDGnSZWuY.gif
I get this script from reply post here : https://stackoverflow.com/a/38680734/5118751 the script is working fine on Jsfiddle and also when i'm directly load the script on html.