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

  • SEARCH
  • Home
  • 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 525001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:37:35+00:00 2026-05-13T08:37:35+00:00

Ive been writing a simple jquery function that turns a div with a list

  • 0

Ive been writing a simple jquery function that turns a div with a list of images into a carousel. Here is the markup..

<div id="carousel">
  <ul>
   <li><img src="images/music1.jpg" /></li>
   <li><img src="images/music2.jpg" /></li>
   <li><img src="images/music3.jpg" /></li>
  </ul>
 </div>

and in my carousel.js file i have the follow function..

//Function turns a div with a list of images into a carousel
//=====
jQuery.fn.makeCarousel = function({slideWidth, numSlides, transTime, interval}) {
 //== Get Element and store id==//
 var id = $(this).attr("id");
 var element = "#" + id;

 // Function
 setInterval(function(){
  //Store Variables
  var currentLeft = $(element + ' ul').css("left");
  var left = parseFloat(currentLeft, 10);
  var moveBy = left - slideWidth;

  //Slide the list, and stop it being moved out of bounds
  if(moveBy < ((numSlides - 1) * slideWidth) * -1) {
   $(element + ' ul').animate({left : "0px" }, transTime);
  } else {
   $(element + ' ul').animate({left : moveBy + "px" }, transTime);
  }
 },interval);
};

Im going to tidy up the code after, im relativley new to jquery.

I then have the following in the header of the html..

<script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="scripts/carousel.js" type="text/javascript"></script>

 <script type="text/javascript">
  $(function() {

   $('div#carousel').makeCarousel({
    slideWidth: 500, 
    numSlides: 3, 
    transTime: 2000, 
    interval: 3000
   });

  });
 </script>

You can see ive included the jquery core, my carousel script, and then ive called the make carousel method on the div and passed some settings in.

Now, this function runs fine in firefox, but not in IE, Safari, Chrome, and Opera.

  • IE says: “Object doesnt support this property or method” and points to the line above where i call “$(‘div#carousel’).makeCarousel“.

  • Chrome gives 2 errors: The First says “Uncaught TypeError: Object # has no method ‘makeCarousel'” and the next says “Uncaught SyntaxError: Unexpected token {” and points to the line where i declare the function: “jQuery.fn.makeCarousel = function({slideWidth, numSlides, transTime, interval}) {“

Im at a bit of a loss with this, have i declared the function correctly? What else could it be? It works really nicely in firefox but not in anything else.

Any help with this would be greatly appretiated!
Thanks!

Tom

  • 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-13T08:37:35+00:00Added an answer on May 13, 2026 at 8:37 am

    Your function definition is incorrect. It should take a list of parameters but the syntax you are using creates an object, not a parameter list.

    Try this:

    jQuery.fn.makeCarousel = function(options) {
      options = jQuery.extend({slideWidth : 0, numSlides: 1, transTime: 100, interval: 5000}, options);
    
      return $(this).each( function() {
    
       var $this = $(this);    
       // Function
       setInterval(function(){
          //Store Variables
          var currentLeft = $(element + ' ul').css("left");
          var left = parseFloat(currentLeft, 10);
          var moveBy = left - options.slideWidth;
    
          //Slide the list, and stop it being moved out of bounds
          if(moveBy < ((options.numSlides - 1) * options.slideWidth) * -1) {
               $this.find('ul').animate({left : "0px" }, options.transTime);
          } else {
               $this.find('ul').animate({left : moveBy + "px" }, options.transTime);
          }
        },options.interval);
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 296k
  • Answers 296k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use invert on your hash. It exchanges keys and values:… May 13, 2026 at 7:10 pm
  • Editorial Team
    Editorial Team added an answer With XSLT 2.0 (but not with XSLT 1.0) you can… May 13, 2026 at 7:10 pm
  • Editorial Team
    Editorial Team added an answer Derived.hpp:n: error: invalid use of incomplete type ‘struct N::Base’ This… May 13, 2026 at 7:10 pm

Related Questions

I've been searching around this morning and I'm not finding any simple solutions... basically,
I have a jQuery selector, which has a chained function. Inside the function I
I'm writing a little web-based utility for my brother who needs to merge columns
I'm writing jQuery for a page that is a complex mess of many DOM
I've been reading about dependency injection and have a simple question. I can understand

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.