Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Bookmark links and a static page banner.

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
Home » Discuss » DU Groups » Computers & Internet » Website, DB, & Software Developers Group Donate to DU
 
MostlyLurks Donating Member (738 posts) Send PM | Profile | Ignore Fri Jul-15-05 11:54 AM
Original message
Bookmark links and a static page banner.
Hi All,

I hope someone can help a newb and a lUser. I'm trying to design a reasonably simple web site for the company I work for - hiring a designer is not an option due to $ problems. I am using XHTML and CSS to make it happen and have used a "test and see what happens" method to build the page because I'm not really that familiar with HTML, CSS, etc (just more familiar than any of my co-workers). I have run into something I can not solve.

I have positioned the company logo at the top of the page, similar to a banner that spans across the page. When the user scrolls down, the logo stays in place at the top of the screen (via CSS positioning) while the text in the body moves, which is exactly what I want. As far as I can tell, the text scrolls behind the banner, so it is actually scrolling all the way to the top of the screen, but can't be seen behind the banner. Hope that makes sense.

Let's say the page has a link that jumps to another part of the same page. So there's a link that they can click to go to "Department Whatever" and when they click that link, I want the heading that says "Department Whatever" to come up to the top, directly under the banner.

Here's the problem: when the in-page link is clicked, it brings the heading up to the ABSOLUTE top of the viewing space, which is occupied by the banner. The end result is that the heading is invisible behind the banner, and it looks like the page has scrolled to a random point in the text stream.

Is there a way correct this and make it work properly i.e. make the bookmark scroll to the top of the "visible" body space? The best I've managed so far is to place the bookmark a few lines above the real point where it should be, but it's haphazard, doesn't look quite right and works differently depending on screen resolution.

I hope that makes some manner of sense. Thanks for any help you can provide.

Mostly.
Refresh | 0 Recommendations Printer Friendly | Permalink | Reply | Top
charlie Donating Member (1000+ posts) Send PM | Profile | Ignore Sun Jul-17-05 05:25 AM
Response to Original message
1. With CSS and HTML?
No, I don't believe so.

It can be done with Javascript, though. Kind of a wonky solution, but if you want to try it, it works. Paste this into your pages:

<script type="text/javascript">
var offFromTop=95;
var lnx;
var tID;
var reg;
function setUp(){
if(!!(document.addEventListener)&&!!(window.pageYOffset!='undefined')){
reg=[];
lnx=document.getElementsByTagName('a');
for(var i=0;i<lnx.length;i++){
if(!!(lnx[i].href)){
if(lnx[i].href.indexOf('#')>-1){
lnx[i].addEventListener('click',adjustScroll,false);
reg.push(i);
}
}
}
document.addEventListener('unload',deRef,false);
}
}
function adjustScroll(){
clearTimeout(tID);
tID=setTimeout('window.scrollTo(0,window.pageYOffset-offFromTop)',50);
}
function deRef(){
for(var i=0;i<reg.length;i++){
lnx[reg[i]].removeEventListener('click',adjustScroll,false);
}
lnx=null;
}
window.onload=setUp;
</script>

and change the offFromTop variable to the distance you want the scroll to stop from the top in pixels.

It works fine in Firefox/Mozilla and Opera 7-8, fails silently in IE (which won't be a problem, since IE can't do fixed positioning yet) and other browsers that don't have the properties/methods it uses. It should work in Konquerer and Safari, but I can't say for sure -- I don't have a Mac and my Linux partition is munged right now.

Here's a readymade test page you can copy and paste:

<html>
<head><title></title>
<style type="text/css">
.banner {position:fixed; top:0px; left:20px; width:728px; height:90px}
b {color:#990000}
b a {color:#990000}
.blk {width:200px; border:1px solid #000000; background-color:#ccccff}
#d0 {height:200px}
#d1 {height:800px}
#d2 {height:1000px}
#d3 {height:1000px}
</style>
<script type="text/javascript">
var offFromTop=95;
var lnx;
var tID;
var reg;
function setUp(){
if(!!(document.addEventListener)&&!!(window.pageYOffset!='undefined')){
reg=[];
lnx=document.getElementsByTagName('a');
for(var i=0;i<lnx.length;i++){
if(!!(lnx[i].href)){
if(lnx[i].href.indexOf('#')>-1){
lnx[i].addEventListener('click',adjustScroll,false);
reg.push(i);
}
}
}
document.addEventListener('unload',deRef,false);
}
}
function adjustScroll(){
clearTimeout(tID);
tID=setTimeout('window.scrollTo(0,window.pageYOffset-offFromTop)',50);
}
function deRef(){
for(var i=0;i<reg.length;i++){
lnx[reg[i]].removeEventListener('click',adjustScroll,false);
}
lnx=null;
}
window.onload=setUp;
</script>
</head>
<body>
<img class="banner" src="banner.gif" />
<div id="d0" class="blk"></div>
<b><a href="#one">GO TO ANCHOR ONE</a></b><br />
<b><a href="#two">GO TO ANCHOR TWO</a></b><br />
<b><a href="#three">GO TO ANCHOR THREE</a></b><br />
<div id="d1" class="blk"></div>
<a name="one"><b>--------- ONE ---------</b></a><br />
<div id="d2" class="blk"></div>
<a name="two"><b>--------- TWO ---------</b></a><br />
<div id="d3" class="blk"></div>
<a name="three"><b> --------- THREE ---------</b></a><br />
<div id="d4" class="blk"></div>
</body>
</html>

Just change the image source to point to your logo, the image dimensions in the CSS, and the offFromTop value.
Printer Friendly | Permalink | Reply | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Sun Dec 22nd 2024, 09:43 AM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » DU Groups » Computers & Internet » Website, DB, & Software Developers Group Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC