[Javascript]Scripting being Difficult

All is well...
Loyal Member
Joined
Feb 22, 2006
Messages
1,520
Reaction score
0
Here's the script:
Code:
function JSFX_FloatTopLeft()
{
	
	var startX1 = 1250, startY1 = 100;
	var startX2 = 1200, startY2 = 100;
	var startX3 = 1000, startY3 = 100;
	var startX4 = 950, startY4 = 100;
	var startX5 = 900, startY5 = 100;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
		if(screen.height == 1600 && screen.width == 1200)
		{
		el.x = startX1; el.y = startY1;
		}
		else if(screen.height == 1400 && screen.width == 1050)
		{
		el.x = startX2; el.y = startY2;
		}
		else if(screen.height == 1280 && screen.width == 1024)
		{
		el.x = startX3; el.y = startY3;
		}
		else if(screen.height == 1152 && screen.width == 864)
		{
		el.x = startX4; el.y = startY4;
		}
		else(screen.height == 1024 && screen.width == 768)
		{
		el.x = startX5; el.y = startY5;
		}
		return el;
	}
	window.stayTopLeft=function()
	{
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 40);
	}
	ftlObj = ml("divStayTopLeft");
	stayTopLeft();
}
JSFX_FloatTopLeft();

Now here's the story behind it... lol
I was perfectly content with it until my friend told me that the div was way off the screen and had to scroll to see it. So I added in some if statements to check screen resolutions. As soon as I do that the script stops working entirely...
Anyone see any problems with it?

Works fine and dandy with no if statements or anymore variables:
Code:
function JSFX_FloatTopLeft()
{
	
	var startX = 1250, startY = 100;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
		el.x = startX; el.y = startY;
		return el;
	}
	window.stayTopLeft=function()
	{
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 40);
	}
	ftlObj = ml("divStayTopLeft");
	stayTopLeft();
}
JSFX_FloatTopLeft();

Any ideas to what's up?

Preview of working code: http://wh005h.com/ro/index.php

**Edit**
As a side note if anyone knows how to make the server time on it show a static time zone that would be awesome too ^_^
Good ahead and post it here rather than starting a new topic =p
time.getSeconds() and the others are clientside (flash runs clientside) but I need for it to display a static hour not varying by browser. Doesn't really matter what hour just for it show 1 timezone lol

Code:
time=new Date(); // time object
var seconds = time.getSeconds()
var minutes = time.getMinutes()
var hours = time.getHours()
if (hours<12) {
	ampm = "AM";
	} 
	else{
		ampm = "PM";
	}
while(hours >12){
		hours = hours - 12;
			}
if(hours<10)
	{
	hours = "0" + hours;
	}
if(minutes<10)
	{
	minutes = "0" + minutes;
	}
if(seconds<10)
   {
	seconds = "0" + seconds;
	}
if(hours == 00)
	{
		hours = 12
	}
clock_txt.text = hours + ":" + minutes + ":" + seconds +" "+ ampm;
 
It's a floating div, it scrolls with the page. When you scroll down it follows
Right now there's an error in my page with some sql stuff gimme a sec to fix it since it's making the div not work either lol
 
well i couldnt see the div because the page is to big for my monitor what res is it

i saw the div and i scrols as i do so it works in Firefox
if your using IE it disables scripts as a default (thanks username1)
 
No it works in both lol, I havn't had any problems in different browsers.
That's my problem... If you read it says the div appears way off screen, like you said. The if statements in the code are used to figure out where to place the div according to resolution so that problem would be fixed. Yet, when I put them in there it screws it up entirely.

**Edit**
Well apparently I screwed over my screenshot viewer as well lol
Lemme fix it too... uhh lol
**Edit2**
K, fixed it lol did something stupid ^_^
 
well IMO its not because of your div its cuz your site layout was made to big its like widescreen for no reason try scaling it down
and for your clock i suggest a flash clock let me look for one reall quick

EDIT 1: flash clocks Flash Clock
or
a tutorial
Flash Clock
 
It looks fine for me lol. Anything smaller and it would be too small...
What resolution are you on right now? It looks great in 1400x1050 and 1600x1200

Also my clock is the same as the clock on those sites (they all use the same functions as mine) except for the timezone ones which is what I'm trying to make right now lol, but I want mine to be in fla/editable format
 
It looks fine for me lol. Anything smaller and it would be too small...
What resolution are you on right now? It looks great in 1400x1050 and 1600x1200

Also my clock is the same as the clock on those sites (they all use the same functions as mine) except for the timezone ones which is what I'm trying to make right now lol, but I want mine to be in fla/editable format
hahaha you have to use main stream Resolutions for a site to be viewed my everyone if i was on a 800*600 laptop it would take forever
and same with me 1024*768
try making it a main layout such as 800*900 1000*9000
850*1119(blogs)
also the FLA clocks are ok but id use a java one on your site now i think bout it heres a code
Code:
var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();

   document.theClock.theTime.value = "" 
                                   + tDate.getHours() + ":" 
                                   + tDate.getMinutes() + ":" 
                                   + tDate.getSeconds();
   
   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

//-->

</script>
<body onload="StartClock()" onunload="KillClock()">
<center><form name="theClock">
<input type=text name="theTime" size=8>
<form></center>

or

Code:
<SCRIPT LANGUAGE="JavaScript">
<!--  Clock --
var timerID = null
var timerRunning = false

function stopclock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function startclock(){
    stopclock()
    showtime()
}

function showtime(){
    var now = new Date()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var seconds = now.getSeconds()
    var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
    timeValue  += (hours >= 12) ? " P.M." : " A.M."
    document.clock.face.value = timeValue 
    timerID = setTimeout("showtime()",1000)
    timerRunning = true
}
//-->
</SCRIPT>
<BODY onLoad="startclock()">
<!-------------------------------------------------------------------------------------------->
<form name="clock" onSubmit="0">
<INPUT TYPE="text" NAME="face" SIZE=11 VALUE ="....Initializing....">
</form>

i have no clue which one you want
 
Yah I tried a java clock but I couldn't align it just the way I wanted it lol. I want it exactly centered over that image in that exact place with that exact text. The only way for me to do that was with flash lol

Wow... how can anyone read anything in such low resolutions... it's so grainy and fat... lol My icons are as big as my hand lol, I have no more desktop anymore! It's just full of icons! Why would anyone want such a low resolution? 1280x1024 is okay but any lower and that's just stupid... You can't even read Rz...
Plus I just went and measured some other sites and mine is pretty much the same width. It might be because it's centered as well ^_^

Also, still need help with that script lol The clock I can fix with a bit of thinking I bet

**Edit**
Yes much more friendly without it being centered lol
How's that kip?

**Edit2**
Aight fixed it lol, all better ^_^ good in all resolutions =p

**Edit3**
Okay, flash had a gettimezoneoffset so I got it to work, hurray!
It now shows a constant pst time ^_^ hurray for wh005h! He pwns joo! lol thanks kip for pointing out the huge resolution changes lol
 
Last edited:
sage

You know, HTML and CSS provides alignment primitives... you can have divs aligned relative to the browser window IIRC, like a header/footer type of thing. Also, see "float" CSS property.

...and that Javascript is *awful*. I'm running 2048x1536 BTW.

Moral of lesson: use alignment primitives and CSS whenever possible. Javascript is NOT to be abused like this.
 
Yah I tried a java clock but I couldn't align it just the way I wanted it lol. I want it exactly centered over that image in that exact place with that exact text. The only way for me to do that was with flash lol

Wow... how can anyone read anything in such low resolutions... it's so grainy and fat... lol My icons are as big as my hand lol, I have no more desktop anymore! It's just full of icons! Why would anyone want such a low resolution? 1280x1024 is okay but any lower and that's just stupid... You can't even read Rz...
Plus I just went and measured some other sites and mine is pretty much the same width. It might be because it's centered as well ^_^

Also, still need help with that script lol The clock I can fix with a bit of thinking I bet

**Edit**
Yes much more friendly without it being centered lol
How's that kip?

**Edit2**
Aight fixed it lol, all better ^_^ good in all resolutions =p

**Edit3**
Okay, flash had a gettimezoneoffset so I got it to work, hurray!
It now shows a constant pst time ^_^ hurray for wh005h! He pwns joo! lol thanks kip for pointing out the huge resolution changes lol

yup any time man resoultions are key to sucess LOL
but you site is coming along
and 1024*768 is not bad on a 17 inch monitor i may buy a 24 this year!
 
Back