I\'m looking for a way to create a slide out \'show more\' feature on my responsive site, which cuts off after two lines of a paragraph.
I\'ve achie
Starting from your fiddle and wrapped the content into a I also removed the HTML: CSS: I'm assuming setting the I attached a click event to the "show more" link which switches the classes on the div using jQueryUI switchClass(): The above code is an example only but should get you started into the right direction.content, used for selection and a class called hideContent which will be swapped with showContent when clicking the show more/show less link.
the text was in. The text is now within the content-div and we are also now able to apply correct height and line-height settings.
.hideContent {
overflow: hidden;
line-height: 1em;
height: 2em;
}
.showContent {
line-height: 1em;
height: auto;
}
line-height will ensure it is the same in all browsers. I'm not 100% certain on that though.$(".show-more a").on("click", function() {
var $this = $(this);
var $content = $this.parent().prev("div.content");
var linkText = $this.text().toUpperCase();
if(linkText === "SHOW MORE"){
linkText = "Show less";
$content.switchClass("hideContent", "showContent", 400);
} else {
linkText = "Show more";
$content.switchClass("showContent", "hideContent", 400);
};
$this.text(linkText);
});
JsFiddle Demo - show more / show less and applying line-height and animation
$(".show-more a").on("click", function() {
var $this = $(this);
var $content = $this.parent().prev("div.content");
var linkText = $this.text().toUpperCase();
if (linkText === "SHOW MORE") {
linkText = "Show less";
$content.switchClass("hideContent", "showContent", 400);
} else {
linkText = "Show more";
$content.switchClass("showContent", "hideContent", 400);
};
$this.text(linkText);
});div.text-container {
margin: 0 auto;
width: 75%;
}
.hideContent {
overflow: hidden;
line-height: 1em;
height: 2em;
}
.showContent {
line-height: 1em;
height: auto;
}
.showContent {
height: auto;
}
h1 {
font-size: 24px;
}
p {
padding: 10px 0;
}
.show-more {
padding: 10px 0;
text-align: center;
}