E
Erwin Moller
Thomas Allen schreef:
Hi Thomas,
[Please don't qoute signatures. Any good newsreader will do that for you
automagically.]
I see others have pointed out already JQuery is not considered (good)
JavaScript by many developers. (But it is JavaScript of course.)
David Mark, the one you are having a not-so-friendly discussion with,
actually took the time to study JQuery (different versions) quite
thoroughly and he published his results in here earlier.
His findings, plus what other people I respect in comp.lang.javascript
think about JQuery, plus my own programming experience and natural
paranoid, gives me a very clear picture of JQuery: stay away from it.
Bottomline: I still cannot help you with your problem. Your simplified
version is still based on JQuery and I have no clue how JQuery's
internals work. :-/
Sorry I cannot be of help. Maybe try a JQuery forum I suggested earlier.
Good luck.
Regards,
Erwin Moller
PS: a little reflection if I may:
I can imagine you feel frustrated now. You have a problem, you post a
friendly message and ask for help.
Then people in here tells you to loose JQuery first, a lib you like,
before they can/will help.
But for your own sake: take a little distance, don't make it personal,
and look at the problem again: A lot of experienced JavaScript
developers advise you to avoid JQuery. Maybe this is actually good advise?
Why don't you roll your own full JavaScript instead? I always do that
and it gives me a lot of satidfaction when a difficult job is done right
by me in 'pure' JavaScript/DOM (no libs). Do you really need JQuery?
With a little study you can start doing all DOM manipulation yourself.
That way you will also be able to debug a lot better than now.
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Thomas Allen schreef:
I'm trying to use SetTimeout to rotate some image sources, and I can't
get it to work. I know that there are other ways to pull this off, but
I'm curious as to what I need to change to get this script to work:
(function($) {
$(document).ready(function() {
var sponsors = $('.sponsors');
var sponsor_images = sponsors.find('img').remove();
var sponsor_frame = $('<img>').attr('src',
setTimeout(function() {
for(var i = 0; i < sponsor_images.length; i++) {
return $(sponsor_images).attr('src');
};
}, 3000)
);
sponsors.html(sponsor_frame);
});
}) (jQuery);
If it isn't clear, here's what should happen:
1. Find the sponsor block
2. Extract the images as a jQuery object, removing them
3. Create a new image node
4. Set this image's source to change every three seconds to the next
one from the extracted images object
I've verified that the only part of the script that isn't working
properly is the setTimeout call, so I must be doing something wrong.
In case it's at all useful, here's the accompanying markup:
<div class="sponsors">
<img src="/handa/images/sponsors/aecom.png" alt="AECOM" />
<img src="/handa/images/sponsors/cdm.png" alt="CDM" />
<img src="/handa/images/sponsors/pankow.png" alt="Charles Pankow
Foundation" />
<img src="/handa/images/sponsors/moretrench.png" alt="Moretrench" />
<img src="/handa/images/sponsors/figg.png" alt="Figg" />
<img src="/handa/images/sponsors/hntb.png" alt="HNTB" />
<img src="/handa/images/sponsors/kiewit.png" alt="Kiewit" />
<img src="/handa/images/sponsors/mcgraw.png" alt="McGraw Hill
Construction - ENR" />
<img src="/handa/images/sponsors/weidlinger.png" alt="Weidlinger
Associates Inc. - Consulting Engineers" />
</div>
And I greatly appreciate any help!
Thanks,
Thomas
Here's a simpler alternative:
(function($) {
$(document).ready(function() {
var sponsors = $('.sponsors');
var sponsor_images = sponsors.find('img').remove();
var sponsor_frame = $('<img>');
for(var i = 0; i < sponsor_images.length; i++) {
setTimeout("sponsor_frame.attr('src', $(sponsor_images).attr
('src'))", 3000);
};
sponsors.html(sponsor_frame);
});
}) (jQuery);
However, I don't understand scope inside of setTimeout: I get
"undefined" errors for all of the variables in the setTimeout command,
and I'm not too keen on making each one global.
Thomas
If you can rewrite your script in such a way you don't use $ and JQuery,
maybe it becomes clearer and debugable (for me).
If you MUST use JQuery, why don't you post to their forum?
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Hi Erwin,
Hi Thomas,
[Please don't qoute signatures. Any good newsreader will do that for you
automagically.]
I know, but I felt that this was a more JavaScript-oriented question.
I see others have pointed out already JQuery is not considered (good)
JavaScript by many developers. (But it is JavaScript of course.)
David Mark, the one you are having a not-so-friendly discussion with,
actually took the time to study JQuery (different versions) quite
thoroughly and he published his results in here earlier.
His findings, plus what other people I respect in comp.lang.javascript
think about JQuery, plus my own programming experience and natural
paranoid, gives me a very clear picture of JQuery: stay away from it.
Bottomline: I still cannot help you with your problem. Your simplified
version is still based on JQuery and I have no clue how JQuery's
internals work. :-/
Sorry I cannot be of help. Maybe try a JQuery forum I suggested earlier.
Good luck.
Regards,
Erwin Moller
PS: a little reflection if I may:
I can imagine you feel frustrated now. You have a problem, you post a
friendly message and ask for help.
Then people in here tells you to loose JQuery first, a lib you like,
before they can/will help.
But for your own sake: take a little distance, don't make it personal,
and look at the problem again: A lot of experienced JavaScript
developers advise you to avoid JQuery. Maybe this is actually good advise?
Why don't you roll your own full JavaScript instead? I always do that
and it gives me a lot of satidfaction when a difficult job is done right
by me in 'pure' JavaScript/DOM (no libs). Do you really need JQuery?
With a little study you can start doing all DOM manipulation yourself.
That way you will also be able to debug a lot better than now.
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare