T
Thomas Allen
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,
Thomass
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,
Thomass