简体   繁体   中英

Display an “expand” button at the bottom of a div only in the case that it's taller than a certain height

I have a stream of "posts" on the front page of my site that are each represented as individual <div> s. The posts can be of any height. When a post is less than 350px tall, I want to display the full post. When it is MORE than 350px tall, I want to display the first 350px , hide the rest with overflow: hidden , and give the user an "expand" button to show the whole thing:

How do I achieve this using as little Javascript as possible (ideally none!)?

<script>
$(document).ready(function() {
  var divheight = $('#whateverdiv').height();
  if(divheight>350)
  {
     $('#thisbutton').show();
  }
});
</script>

<style>
#thisbutton
{
   display:none;
}
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM