sof_engi08
sof_engi08

Reputation: 27

how to set scroll on the div by setting height to percent

I have a div i want to make it scroll top . when i set its height to pixel that time i am getting the scroll but when i am setting it to percent i am not getting scroll

<div id="lblAlert" runat="server" class="warning-message" style="overflow:auto" >

// working code

scrollfun()
{
lblAlert.style.height = 65; 
}
// not working code
scrollfun()
{
lblAlert.style.height = '2%'; 
}

How will i do this,how can i convert pixel to percent ?? please help

Upvotes: 1

Views: 637

Answers (2)

Matt Hintzke
Matt Hintzke

Reputation: 7984

Heres my jsFiddle that does what you want http://jsfiddle.net/F8Qpx/

changeHeight = function (){
var obj = document.getElementById('lblAlert');
var parent = obj.parentNode;
obj.style.height = (parent.offsetHeight/100)*2 + "px";//Make 2%
}​

This code should work

Upvotes: 1

MicroEyes
MicroEyes

Reputation: 3742

try to get height of parent element using

var element_Height = $(element).parent().css('height');

and calculate scroll height from it using

height = (2 / 100) * element_Height;

This will give you height to scroll.

Upvotes: 2

Related Questions