I am creating a final container for an author page on a book publishing website. Some authors have more summary content, while others have less content. I want to enable / disable the display of the over / under button dynamically when the height of the div container crosses the cut height (180 pixels). Thus, dynamic control of the height of the container div (180px and the original height) is obtained. I need a piece of code that works great in all browsers.
I have the code implemented here:
http://jsfiddle.net/rraagghhu/9dgs6432/3/
HTML:
<div class = "container"> <div class="info-wrapper"> <div class="info"> Chetan Bhagat is the author of six blockbuster books.These include five novelsโFive Point Someone (2004), One Night @ the Call Center (2005), The 3 Mistakes of My Life (2008), 2 States (2009), Revolution 2020 (2011), the non-fiction title What Young India Wants (2012) and Half Girlfriend (2014). Chetan's books have remained bestsellers since their release. Four out his five novels have been already adapted into successful Bollywood films and the others are in process of being adapted as well. The New York Times called him the 'the biggest selling English language novelist in India's history'. Time magazine named him amongst the '100 most influential people in the world' and Fast Company, USA, listed him as one of the world's '100 most creative people in business'. Chetan writes columns for leading English and Hindi newspapers, focusing on youth and national development issues. He is also a motivational speaker and screenplay writer. Chetan quit his international investment banking career in 2009 to devote his entire time to writing and make change happen in the country. He lives in Mumbai with his wife, Anusha, an ex-classmate from IIM-A, and his twin boys, Shyam and Ishaan. You can email him at info@chetanbhagat.com or fill in the Guestbook with your feedback. You can also follow him on twitter (@chetan_bhagat) or like his Facebook fanpage (https://www.facebook.com/chetanbhagat.fanpage). </div> <a href="#" class="more">(more)</a> <a href="#" class="less">(less)</a> </div> <div class = "footer"> THIS IS FOOTER </div> </div>
CSS:
.container{ background-color: yellow; } .footer{ background-color: yellow; } .info-wrapper { height: auto; position: relative; width: auto; padding: 0 0 2.5em 0; background-color: red; } .info { max-height: 180px; height: auto; width: auto; overflow: hidden; position: relative; text-align: justify; } .info:after, .aftershadow { bottom: 0; width: auto; height: auto; } .info-wrapper a { left: 50%; position: relative; font: 700 .67em/1.25em Arial; text-align: center; text-decoration: underline; cursor: pointer; } .less { height: auto; display: none; } .more { display: none; }
Jquery:
if($(".info")[0].scrollHeight > $(".info").height()) { $("a.more").show(); } $("a.more").click(function(e){ e.preventDefault(); $(".info").css({"overflow": "visible"}); $("a.less").show(); $("a.more").hide(); return false; }); $("a.less").click(function(e){ e.preventDefault(); $(".info").css({"overflow": "hidden"}); $("a.more").show(); $("a.less").hide(); return false; });
As you can see, the footer remains in absolute position. If you press the button more, then (less) should go down, below this should be the footer. Is it possible to enable / disable the dynamic show more / less button while reducing / expanding the browser?
source share