473,499 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

resizing some content on page Load

Hi,

I'm looking for the way to resize an element when the page loading.

I'm doing some test and I've try :

function placeHeader () {
var x;
document.getElementById('header').style.display = 'visible';
for (x = 0; x < 150;x++) {
document.getElementById('header').style.width = x + "px";
}
}

but nothing appear

Any idea thx in advance
Jul 23 '05 #1
2 1166
Alexandre Jaquet a écrit :
Hi,

I'm looking for the way to resize an element when the page loading.

I'm doing some test and I've try :

function placeHeader () {
var x;
document.getElementById('header').style.display = 'visible';
for (x = 0; x < 150;x++) {
document.getElementById('header').style.width = x + "px";
}
}

but nothing appear

Any idea thx in advance


oups I make a mistake with the display value ..
Jul 23 '05 #2
Alexandre Jaquet wrote:
Hi,

I'm looking for the way to resize an element when the page loading.

I'm doing some test and I've try :

function placeHeader () {
var x;
document.getElementById('header').style.display = 'visible';
for (x = 0; x < 150;x++) {
document.getElementById('header').style.width = x + "px";
}
}

but nothing appear

Any idea thx in advance


function placeHeader () {
var ele = document.getElementById('header');
if ( ele && ele.style ){
ele.style.display = '';
for (var x=0; x<150; x++) {
ele.style.width = x + "px";
}
}
}

1. Checks that getElementById returned something

2. Checks that whatever ele is, it supports the style object

3. Makes one call to getElementById, not 152 as in the original

So should be more robust and use fewer CPU resources. However, given
that there is no lag between each loop, it will run so quickly that
most visitors will not see the element grow, it will just appear to
be full size straight up.

If you want it to "grow", you have to use setTimeout with a suitable
value (say 10 milliseconds) then the element 'header' will take about
1.5 seconds to reach full size. To get a faster transition, use
bigger steps.

Here's an example based on one I baked earlier:

<script type="text/javascript">
function growEle(z){
if (document.getElementById) {
var el = document.getElementById(z);
} else {return}

if ( el && el.style ){
var w = 0;
var maxWidth = 150; // Max width of element
var d = 10; // Delay between steps
var s = 5; // Step to grow by

// Stop timer if it's already running
if (el.timer) window.clearTimeout(el.timer);

el.timer = window.setInterval(function(){ // Start timer
if ( w > maxWidth ) { // If reached limit
el.style.width = maxWidth + 'px'; // Set width to limit
window.clearTimeout(el.timer); // Stop timer
el.timer = null; // Clear timer
}
el.style.width = w + 'px'; // Set the width
w += s; // Increment width
}, d); // End timer
}
}

</script>
<input type="button" value="Grow 'header'" onclick="
growEle('header');
">
<div style="border: 1px solid red; width: 10px;" id="header">blah
</div>

--
Rob
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
32026
by: Bryan R. Meyer | last post by:
Hello Everyone, The problem of browser resizing has become an issue for me. While redesigning my webpage, I set the left and right margins to be auto so that my content would be centered. ...
5
2621
by: Robert J. O'Hara | last post by:
For some time I've made use of the max-width property in CSS to cause my pages to appear as a centered block against a contrasting background. This works well in new browsers (Mozilla, etc.) and...
3
5359
by: bismarkjoe | last post by:
Hello, I am trying to set the widths on the columns of a DataGrid component, and I'm not sure if I'm doing it correctly. My code is below: //load some inital data table = db.GetDataTable(...
10
4127
by: David W. Simmonds | last post by:
I have a DataList control that has an Image control in the ItemTemplate. I would like to resize the image that goes into that control. I have a series of jpg files that are full size, full...
0
2078
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
3
4466
by: PCgeek | last post by:
sorry moved this over to javascript forum, didn't mean to post 2x! Hi guys, I'm trying to put the finishing touches on my website and could really use some help on this particular issue. My page...
9
2918
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
9
5266
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
1
2670
helpmepls
by: helpmepls | last post by:
i have a site where I have an iframe mainFrame which loads page content from the main menu (top horizontal menu). within this mainFrame is a second menu to left specific to the loaded page, and...
1
4863
by: hemantkamb | last post by:
Hi…. I have created one website with Master and content page . I have taken TreeView Control on master page. And I wants that when I click to tree node the value of tree node is added to...
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.