scroll - Use jQuery to display controls only in case of hidden content -
i want display controls scroll contents of div in case of overflow. i'm not sure have syntax right - appreciated.
my html
<div class="container"> <div class="content"> <div class="line-1">line 1</div> <div class="line-2">line 2</div> <div class="line-3">line 3</div> <div class="line-4">line 4</div> <div class="line-5">line 5</div> <div class="line-6">line 6</div> <div class="line-7">line 7</div> <div class="line-8">line 8</div> <div class="line-9">line 9</div> </div> <div class="buttons"> </div> </div> <div class="container"> <div class="content"> <div class="line-1">line 1</div> <div class="line-2">line 2</div> <div class="line-3">line 3</div> <div class="line-4">line 4</div> <div class="line-5">line 5</div> <div class="line-6">line 6</div> </div> <div class="buttons"> </div> </div>
my javascript
if ((".content").offsetheight < (".content").scrollheight) { $( ".container .buttons" ).append( "<button>up</button><button>down</button>" ); }
my css
.container { margin-bottom: 20px; } .content { overflow: hidden; height: 100px; padding: 10px; border: 1px solid #ccc; }
you can way.
first need remove height
.content
, check if .content
greater 100
if yes set 100px
height div , append buttons.
your js this
$(".content").each(function(){ if($(this).height() > 100){ $(this).css("height","100px"); $(this).next(".buttons").append( "<button>up</button><button>down</button>" ); } });
Comments
Post a Comment