Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3612336
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:59:11+00:00 2026-05-18T21:59:11+00:00

I have a banner rotator and I wanted to use objects instead of functions

  • 0

I have a banner rotator and I wanted to use objects instead of functions so I could make the code more efficient. Anyway I can’t seem to get setInterval to work. I think it’s got something to do with the object reference. Can anybody explain this? Here’s what I’ve got so far:

window.addEvent('domready', function() {
function set_banner(divid, array)
{
    var banner = $(divid);
    banner.set('html', '<a href=""><img src="" alt=""/></a>');
    var banner_link = $(divid).getElement('a');
    var banner_image = $(divid).getElement('img');

    var delay = 0;  

    for (var keys in banner1array) {
        var callback = (function(key) { return function() {
            banner.setStyle('opacity', 0);
            var object = array[key];
            for (var property in object) {
                if (property == 'href') {
                    var href = object[property];
                }
                if (property == 'src') {
                    var src = object[property];
                }
            }
            if (!banner.getStyle('opacity')) {
                banner.set('tween', {duration:1000});                   
                banner_link.setProperty('href', href);
                banner_image.setProperty('src', src);
                banner.tween('opacity', 1);
            }
        }; })(keys);
        setTimeout(callback, delay);
        delay += 21000;
    }
}

var banner1 = set_banner('banner1', banner1array);
setInterval(function() {set_banner('banner1', banner1array);}, 84000);

var banner2 = set_banner('banner2', banner2array);
setInterval(function() {set_banner('banner2', banner2array);}, 84000);

});

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:59:12+00:00Added an answer on May 18, 2026 at 9:59 pm

    A couple of simple mistake:

     var banner1 = new set_banner('banner1');
                   ^ ---------- creates a new object and uses set_banner as the constructor
                                your code already gets called here
                                and you get a new object back, which in this case has NO use
    
     ....
     setInterval(banner1(), 42000);
                         ^----------------- The parenthesis EXECUTE the function
                                            the RETURN VALUE is then passed to setInterval
                                            BUT... banner1() is NOT a function, so this fails
    

    What you want to do in case that you want to call set_banner after 42 seconds AND pass a parameter is to use an anonymous function which then calls set_banner.

    setInterval(function() { // pass an anonymous function, this gets executed after 42 seconds...
        set_banner('banner1'); // ...and then calls set_banner from within itself
    }, 42000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this banner rotator code: function ban_rot() { //First preload images // counter
I have this banner rotator function: var banners = ['../Graphics/adv/1.gif','../Graphics/adv/2.jpg']; //here put location of
I have this banner rotator which is working fine except for one problem... This
I've wrote the following bit of jQuery for a banner rotator I have: Featured_TopBanner:
Is it advice able to have top banner/Logo as a webview instead of Image
I'm noticing a strange behaviour in Firefox. I have a banner that's positioned absolutely
I have a site http://pintum.com.au/goCruising/ I am using Easy Slider 1.7 with a few
I am developing a banner ads system. Each banner will be stored in the
I'm maintaining a Classic ASP app written in VB Script by an outside company

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.