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 4016770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:46:51+00:00 2026-05-20T09:46:51+00:00

For a better project structure i try to store (build) all my custom jQuery

  • 0

For a better project structure i try to store (build) all my custom jQuery stuff to plugins. Is it possible to optimize the following plugin? I know it is 😉 But i need to learn…

Plugin

$.fn.slide = function(options){
    options = $.extend({
        slideitem: 'img',
        prevclass: '.prev',
        nextclass: '.next'
    }, options);

    var element = $(this);

    // How many items to slide?
    var total = element.find(options.slideitem).length;
    var count = 0;

    // Hide all items but not first item
    element.find(options.slideitem).not(':first').hide();

    // Jump to next item
    element.find(options.nextclass).click(function() {        
        (count == total - 1) ? count = 0 : count++;
        element.find(options.slideitem).hide();            
        element.find(options.slideitem).eq(count).show();
        return false;
    });

    // Jump to previous item
    element.find(options.prevclass).click(function() {
        (count == 0) ? count = total - 1 : count--;
        element.find(options.slideitem).hide();            
        element.find(options.slideitem).eq(count).show();
        return false;                
    });
}

Example HTML

<div id="container">
    <div id="nav"><a href="#" class="prev">Previous</a> <a href="#" class="next">Next</a></div>
    <img src="http://dummyimage.com/250x250/000/fff&text=Image#1" width="250" height="250" alt="Dummy #1"/>
    <img src="http://dummyimage.com/250x250/999/fff&text=Image#1" width="250" height="250" alt="Dummy #2"/>
    <img src="http://dummyimage.com/250x250/BBB/fff&text=Image#1" width="250" height="250" alt="Dummy #3"/>
    <img src="http://dummyimage.com/250x250/CCC/fff&text=Image#1" width="250" height="250" alt="Dummy #4"/>
</div>

Here is a working copy you can play with: http://jsfiddle.net/T4t4z/

Thank You in Advance!

  • 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-20T09:46:51+00:00Added an answer on May 20, 2026 at 9:46 am

    There are a few basic things you can do that won’t decrease readability and will most likely improve performance slightly:

    1. Cache jQuery results. You’re using:

      element.find(options.slideitem)
      

      several times. You could replace this with a cached query:

      var items = element.find(options.slideitem);
      
    2. Chain jQuery operations. Instead of:

      element.find(options.slideitem).hide();            
      element.find(options.slideitem).eq(count).show();
      

      Use:

      element.find(options.slideitem).hide().eq(count).show();
      

    However, I would avoid trying to optimize your code too much before you run into problems.

    If you need to optimize further, check out JSPerf, which is a pretty cool tool that will compare two pieces of JavaScript for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose a Ruby project with the following structure... project/ |-- data | `-- data.yaml
Consider the following Visual Studio project structure ProjectA.csproj AClass.cs ProjectB.csproj References ProjectA Web References
I have a project structure that looks like the following: [Solution Name] doc (documentation)
I am doing an AI project that currently had the following namespace/package structure: My
I'm working on better understanding Linq-to-SQL before using on a real project, so I'm
I am working on a small project for learning PHP better. This project has
I'm working on a project, and we're gonna need some better tools as it's
Could anyone recommend me a good open source .Net based wiki project? Better with
I have a problem concerning folder structure of a built InstallShield suite project. I
Like many people we utilise the tree structure of each TFS project's Iteration field

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.