473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why is this JavaScript image resize script slow?

HaLo2FrEeEk
404 256MB
I wrote some code that basically imitates Lightbox. Images that are too large will stretch the layout of my forum, so this code resizes them to an acceptable width (maintaining aspect ratio) and makes them clickable. When clicked, the page darkens (gradual fade) and a box opens up with the image inside it (gradual fade in). Check out an example here:

http://infectionist.com/forum/viewto...?p=23617#23617

I've always been able to figure out ways to do things I want done, but it's usually hacked together and while i works, it's certainly not the best way to do it. This is one of those cases. It's almost painfully slow on my computer, and I have 8 gigs of RAM and a 512MB GPU (3.0GHz dual core CPU.) Other sites that do this (using either Lightbox or some other code) don't have the same problem, and everything happens very quickly and smoothly.

I think it has to do with how many loops and settimeouts I'm doing, jumping between functions and all that, but I can't seem to pinpoint exactly what's causing the problem. If someone here could be so kind as to take a look at it for me, I would be ever so grateful. Here is a direct link to the Javascript file:

http://infectionist.com/misc/lightybox/lightybox.js

Thanks very much in advance, and please forgive how messy the code is, it makes perfect sense to me, but it gives other people headaches.
Nov 15 '10 #1
2 1934
JKing
1,206 Expert 1GB
What is your definition of slow? It popups and slides in under two seconds for me in firefox.

My computer is also significantly slower.
AMD Athlon 64 3200 2.0 GHZ 2GB RAM
Nov 16 '10 #2
HaLo2FrEeEk
404 256MB
It just seems jumpy. The fadeout is supposed to happen in 40 milliseconds, since I'm adding 10 to the opacity and doing a setTimeout for 5 milliseconds. After that the height and width should grow in 100 milliseconds each, so we're at 240 milliseconds. Finally, the picture fadein should take 40 milliseconds, so all in all this should take less than half a second. Of course, I know Javascript isn't that fast, but taking two seconds to do it's thing is way too long.

Could you just take a look at the code and help me clean things up?
Nov 16 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James Aguilar | last post by:
Hey all, I have a bit of code that implements a suffix array, which is essentially an array of iterators or indexes into a string. The array starts out like this String: ABAB Array: 0123 ...
3
by: jdipalmajr | last post by:
I am using a strongly typed dataset with a design time schema. I load data into the dataset tables from xml. The problem I am having is after the XML load. The first time I Add a row to a table...
1
by: z. f. | last post by:
Hi, i have a dot-net app. the first load is really slow, about 4 seconds at least. next requests are very fast. is there a way to analyze the buttleneck in the load process of a asp-net...
6
by: MadMan2004 | last post by:
Hello all! I'm having a problem with a project I'm working on and I'd like to ask for anyone's input that might be helpful. I'm building a rather large front-end application connecting to an...
52
by: frankgerlach | last post by:
>From my simple performance tests of SOAP it seems that it is about ten times slower than binary object request protocols such as RMI, IIOP or SimpleORB. Is this also YOUR experience ?
0
by: Andy_Khosravi | last post by:
I'm having a problem trying to optimize the performance of one of my A97 databases. I have very slow record navigation after a change I made to the table structure, and I'm not sure how best to...
0
by: ysh8o1 | last post by:
Hi, We upgraded our W2K for a W2K3 server at the beginning of the year. It's purpose is to handle TS distribution of a couple of MS-ACCESS 97 apps stored locally on the server. The server is...
3
by: Chris | last post by:
I have a web app which is, most of the time, very responsive. Occassionally it will slow down as if it is recompiling all the files, a little like the first time you run the app. This slow down...
2
by: bravo | last post by:
hi everyone , i am trying to join two tables , the query is working fine when the records in the tables are less but when the records are in huge numbers say 1-2 million then the system hangs... i am...
4
Niheel
by: Niheel | last post by:
http://bytes.com/images/howtos/technologies_cut_cost_slow_economy.jpgThere's no escaping the slowing economy. Layoffs are being announced and companies are in cost cutting mode. Whether you are a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.