javascript - Jquery Help Need For Div Height -
i'm trying auto height of div, div box setup via css 160px overflow: hidden; how can check auto height more 160px or not via jquery ?
i need because have box have button show more or show less if height not bigger height 160px pass command ... right making box smaller
my code this:
<script type="text/javascript"> $("#show_more_websites").click(function() { var button_value = $("#show_more_websites").attr("value"); var box_height = $('.box_show_websites').outerheight(); if(button_value == "show more") { if(box_height <= "160") { var el = $('.box_show_websites'), curheight = el.height(), autoheight = el.css('height', 'auto').height(); el.height(curheight).animate({height: autoheight}, 500); } $("#show_more_websites").attr('value', 'show less'); } if(button_value == "show less") { var el = $('.box_show_websites'), curheight = el.height(), autoheight = el.css('height', '160px').height(); el.height(curheight).animate({height: autoheight}, 500); $("#show_more_websites").attr('value', 'show more'); } }); </script>
update
here can find code: http://jsfiddle.net/rajbh/
here solution
demo fiddles - note: following fiddle has change in html part increase autoheight using html <br/>
http://jsfiddle.net/rajbh/1/ - autoheight less
http://jsfiddle.net/rajbh/2/ - auto height more
$(document).ready(function() { $("#show_more_websites").click(function() { var button_value = $("#show_more_websites").attr("value"); var el = $('.box_show_websites') var box_height = el.outerheight(); var autoheight = el.css('height', 'auto').height(); el.css('height',box_height+'px'); if(button_value == "show more") { if(autoheight > box_height) { el.height(curheight).animate({height: autoheight}, 500); } $("#show_more_websites").attr('value', 'show less'); } if(button_value == "show less") { curheight = el.height(); autoheight = el.css('height', '160px').height(); el.height(curheight).animate({height: autoheight}, 500); $("#show_more_websites").attr('value', 'show more'); } }); });
Comments
Post a Comment