PDA

View Full Version : Page Scroller (aka custom scroll bar)



atwebresults
12-19-2005, 03:43 AM
Hey guys love this script!!!!! i notices a bug though, it works perfectly in IE and Firefox however in Firefox (and only firefox as far as i can tell) if you click on one of the images (up arrow or down arrow) the javascript console pops up and gives this error:

Error: cross_obj has no properties
Source File: http://www.fiveforksmarket.com/pages/home.php
Line: 82

this site is curently under development and i cannot afford to stop. however the above link will be active however the line number could change so i am providing the code:

LOOK FOR MY NOTE IN ALL CAPS TO INDICATE WHERE THERE ERROR LIES

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive">
<title>Five Forks Market</title>
<STYLE>
body { scrollbar-base-color:#F9E915; }
/*body { scrollbar-face-color: #f9e915; scrollbar-highlight-color: #ce670b; scrollbar-3dlight-color: #ce670b; scrollbar-shadow-color: #F9E915; scrollbar-darkshadow-color: #F9E915; scrollbar-track-color: #ce670b; scrollbar-arrow-color: #ce670b; }*/
/*body { scrollbar-face-color: #ce670b; scrollbar-highlight-color: #F9E915; scrollbar-3dlight-color: #ce670b; scrollbar-shadow-color: #F9E915; scrollbar-darkshadow-color: #ce670b; scrollbar-track-color: #ce670b; scrollbar-arrow-color: #F9E915; }*/
</STYLE>
<SCRIPT LANGUAGE='JavaScript'>
<!--
if (top == window)
location.href = '../index.php?page=about'
-->
</SCRIPT>

</head>

<body bgcolor="#ce670b" leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">

<div id="staticbuttons" style="position:absolute;">
<a href="javascript:" onmouseover="myspeed=-thespeed" onmouseout="myspeed=0"><img
src="arrows_up.gif" border="0"></a>
<a href="javascript:" onmouseover="myspeed=thespeed" onmouseout="myspeed=0"><img
src="arrows_dn.gif" border="0"></a>
</div>

<script>

//Page Scroller (aka custom scrollbar)- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use

var Hoffset=25 //Was 70Enter buttons' offset from right edge of window (adjust depending on images width)
var Voffset=88 //Was 80 Enter buttons' offset from bottom edge of window (adjust depending on images height)
var thespeed=3 //Enter scroll speed in integer (Advised: 1-3)

var ieNOTopera=document.all&&navigator.userAgent.indexOf("Opera")==-1
var myspeed=0

var ieHoffset_extra=document.all? 15 : 0
var cross_obj=document.all? document.all.staticbuttons : document.getElementById? document.getElementById("staticbuttons") : document.staticbuttons

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

***THE FOLLOWING LINE IS WHERE THE ERROR IS OCCURING***
function positionit(){
var dsocleft=document.all? iecompattest().scrollLeft : pageXOffset
var dsoctop=document.all? iecompattest().scrollTop : pageYOffset
var window_width=ieNOTopera? iecompattest().clientWidth+ieHoffset_extra : window.innerWidth+ieHoffset_extra
var window_height=ieNOTopera? iecompattest().clientHeight : window.innerHeight

if (document.all||document.getElementById){
cross_obj.style.left=parseInt(dsocleft)+parseInt(window_width)-Hoffset+"px"
cross_obj.style.top=dsoctop+parseInt(window_height)-Voffset+"px"
}
else if (document.layers){
cross_obj.left=dsocleft+window_width-Hoffset
cross_obj.top=dsoctop+window_height-Voffset
}
}

function scrollwindow(){
window.scrollBy(0,myspeed)
}

function initializeIT(){
positionit()
if (myspeed!=0){
scrollwindow()
}
}

if (document.all||document.getElementById||document.layers)
setInterval("initializeIT()",20)

</script>
</body>

</html>

ddadmin
12-23-2005, 09:25 AM
Hmm I don't get the error in Firefox, just that javascript console popping up, which is normal due to the link being "javascript:". A poor choice nevertheless. You can "fix" this by editing the links to:



<a href="javascript:" onmouseover="myspeed=-thespeed" onmouseout="myspeed=0" onClick="return false"><img
src="arrows_up.gif" border="0"></a>
<a href="javascript:" onmouseover="myspeed=thespeed" onmouseout="myspeed=0" onClick="return false"><img
src="arrows_dn.gif" border="0"></a>


Note the part in red.

jscheuer1
12-23-2005, 11:59 AM
I haven't followed this whole discussion but generally, if you are going to use:


href="javascript:" onclick="return false;"

You may as well go the extra step of using:


href="javascript:void(0);"

That way most non javascript enabled browsers won't get excited about it and you can even dispense with the onclick part.

As I say, generally. I haven't studied this particular case in depth.

atwebresults
12-23-2005, 05:59 PM
I am going to recommend this site to everyone!

ddadmin
12-23-2005, 09:49 PM
Your solution works just as well John :)