Current location: Hot Scripts Forums » General Web Coding » JavaScript » Controling scrolling DIV


Controling scrolling DIV

Reply
  #1 (permalink)  
Old 02-12-07, 08:36 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Controling scrolling DIV

Hello All, I have a <div> with a fixed width and height that I use as a window for requiring othe pages using PHPs' require() command. I have three different pages at the moment that are contained in that <div> and their display and visibility properties are toggled off and on with javascript. I have the overflow property of the <div> set to auto so I can scroll the pages thru the <div>s' window. And their position property is set to absolute so each page is on top of the other. Now, let's say that I am viewing page1 and I have to scroll the <div>s' window in order to view the whole page. Now let's say I have scrolled the page and I decide to view page2 instead, so I click on the page2 button and I have page2 in view, but the position of the scroll doesn't reset back to 0,0. It stays where it was set from the first page. My question is : how do you control the <div>s' inner windows' position with javascript or PHP or ?
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-12-07, 10:23 PM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
Could you post some sample code or a link to the page?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-13-07, 02:49 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Ok Here's the <div> that displays the pages.
Code:
<div id="window_div" style="text-align:center;position:absolute;left:125px;top:219px;width:750px;height:438px;background-color:#ffffe0;border-left:double 4 #000000;border-right:double 4 #000000;overflow:auto;padding-left:16px;padding-right:16px;">
<div id="page0" style="visibility:visible;display:'';"><font style="position:relative;top:50px;font-size:36;">Welcome aboard</font></div>
<div id="page1" style="visibility:hidden;display:none;"><?php require("new1.php"); ?></div>
<div id="page2" style="visibility:hidden;display:none;"><?php require("new4.php"); ?></div>
</div>
As you can see page0 is displayed as defualt. Then with javascript I change the visibility and display properties of the other pages which are both larger than the <div>s' window. When I have page1 or page2 displayed and I scroll the page in the <div> and then toggle the other page to be displayed(page1 or page2) then the scrolled position stays the same. I doesn't reset to the top of the page like I want it to.
__________________
Jerry Broughton

Last edited by job0107; 02-13-07 at 02:56 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-13-07, 03:02 AM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
Could you post the javascript too?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-13-07, 04:05 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
javascript

Code:
function make_visible_1()
{
 document.getElementById("page1").style.visibility = 'visible';
 document.getElementById("page2").style.visibility = 'hidden';
 document.getElementById("page0").style.display = 'none';
 document.getElementById("page1").style.display = '';
 document.getElementById("page2").style.display = 'none';
 }
function make_visible_2()
{
 document.getElementById("page1").style.visibility = 'hidden';
 document.getElementById("page2").style.visibility = 'visible';
 document.getElementById("page0").style.display = 'none';
 document.getElementById("page1").style.display = 'none';
 document.getElementById("page2").style.display = '';
 }
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 02-13-07, 04:41 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
How about this? Haven't checked if it works
Code:
function make_visible_1()
{
 document.getElementById("page1").style.visibility = 'visible';
 document.getElementById("page2").style.visibility = 'hidden';
 document.getElementById("page0").style.display = 'none';
 document.getElementById("page1").style.display = '';
 document.getElementById("page2").style.display = 'none';
 document.getElementById("page1").scrollTop = 0;
 }
__________________
Jack Bauer makes Chuck Norris cry
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 02-13-07, 05:56 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by Vicious View Post
How about this? Haven't checked if it works
Code:
function make_visible_1()
{
 document.getElementById("page1").style.visibility = 'visible';
 document.getElementById("page2").style.visibility = 'hidden';
 document.getElementById("page0").style.display = 'none';
 document.getElementById("page1").style.display = '';
 document.getElementById("page2").style.display = 'none';
 document.getElementById("page1").scrollTop = 0;
 }
That didn't work. But thanks to you this does:
Code:
function make_visible_1()
{
 document.getElementById("page1").style.visibility = 'visible';
 document.getElementById("page2").style.visibility = 'hidden';
 document.getElementById("page0").style.display = 'none';
 document.getElementById("page1").style.display = '';
 document.getElementById("page2").style.display = 'none';
 document.getElementById("window_div").scrollTop = 0;
 }
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Div Scrolling dwoody CSS 2 12-28-06 08:59 PM
Can't Understand java script maverickminds JavaScript 1 07-16-06 02:23 PM
EZ Div Toggle Question AnicoJoe JavaScript 1 05-30-06 08:06 PM
expanding a div to keep image contained pukington HTML/XHTML/XML 0 12-26-05 09:04 AM
CSS Div problem themanmathias CSS 1 09-29-05 09:05 PM


All times are GMT -5. The time now is 07:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.