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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:49:54+00:00 2026-05-17T01:49:54+00:00

I came across this control while using a webapp (this in invite-only beta) and

  • 0

I came across this control while using a webapp (this in invite-only beta) and liked the UI interaction. The webapp was built using prototype/scriptaculous, and we typically use jQuery when building our web apps.. my question is, has anyone seen a jQuery equivalent to this UI element?

A couple of the nice things I like about this approach, instead of the typical radioset approach, is the animated sliding effect of the switch button and still being able to slide on a double-click and the resize cursor.

Since I don’t have a working example of the element, I’ve attached a link to view a screen cap of it in action. 🙂

http://www.youtube.com/watch?v=kdyBodu4bSM

What I’m looking for is a jQuery plugin that can accomplish the same thing.. or a code snippet of something like this in jQuery.
Thanks!

  • 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-17T01:49:55+00:00Added an answer on May 17, 2026 at 1:49 am

    Well, it’s certainly not easy to make yourself. Not easy, but quite fun. This is my first attempt at creating a plugin so please excuse the poor code quality. The code uses (but is not an extension of) jQuery UI. Specifically, it uses the draggable component for the handle, and some UI CSS classes.

    This is certainly a work in progress. It is by no means finished. These are the things I’d like to see done before declaring this thing done:

    1. Keyboard control for moving the handle, for accessibility reasons
    2. Implement WAI-RIA standards, again for accessibility
    3. Set up more options, maybe even events
    4. Refactor the code into something a little more manageable.

    The first two are very important, and is the reason why this code shouldn’t be used yet. You are, however, welcome to hack around the code and play around with it. All suggestions on how this thing might be made to work better are welcome.

    Live demo: http://jsfiddle.net/RDkBL/7/

    (function($) {
    $.fn.slideButton = function(options) {
        // Settings
        var settings = $.extend({
            slideSpeed: 10,
            revertSpeed: 5,
            labelWidth: 0
        }, options);
    
        this.each(function() {
            var container = $(this);
            var label = container.children('label');
            var input = container.children(':radio');
            var maxWidth = 0;
    
            if (label.length != 2 || input.length != 2) {
                throw new Error("The container must contain two radio buttons and two labels");
            }
    
            // move() does the animation associated with
            // state changing for the button
            function move(direction, speed) {
                var amount = direction === 'right' ? halfWidth : -1;
                var duration = (direction === 'right' ? halfWidth - handle.position().left : handle.position().left) * speed;
    
                handle.animate({
                    left: amount
                }, duration);
    
                input.eq(direction === 'right' ? 0 : 1).attr('checked', true);
            }
    
            // Handles changing by checking current state
            function updateState() {
                move(handle.hasClass('on') ? 'right' : 'left', settings.slideSpeed);
                handle.toggleClass('on');
    
                return false;
            }
    
            // Reverts position - think of this as
            // the opposite of updateState()
            function revert() {
                move(handle.hasClass('on') ? 'left' : 'right', settings.revertSpeed);
                return false;
            }
    
            // Adding classes and hiding input elements
            container.addClass('ui-sbutton-container ui-corner-all');
            input.addClass('ui-helper-hidden-accessible');
    
            label.addClass('ui-sbutton-label');
    
            // Setting label widths - if none set,
            // then loop through all of them and use the biggest
            if (settings.labelWidth) {
                maxWidth = settings.labelWidth;
            } else {
                label.each(function() {
                    var w = $(this).outerWidth();
                    if (w > maxWidth) {
                        maxWidth = w;
                    }
                });
            }
    
            // Padding was useful for finding largest width,
            // but will now interfere when setting explicit widths
            label.width(maxWidth).css({
                'padding-left': 0,
                'padding-right': 0
            });
    
            // Getting all important half width for later use
            var halfWidth = (container.outerWidth() / 2);
    
            // Very messy chain that does element creation,
            // insertion and event handling all at once
            var handle = $('<a />')
            .addClass('ui-sbutton-handle  ui-corner-all').hover(function() {
                $(this).toggleClass('ui-sbutton-active');
            }).dblclick(function(){
                updateState();
                return false;
            }).appendTo(container).width(maxWidth - 1).draggable({
                containment: 'parent',
                axis: 'x',
                stop: function(event, ui) {
                    var left = $(this).position().left;
                    if ((left > (halfWidth - 1) / 2 && handle.hasClass('on')) || (left < (halfWidth / 2 - 1) && !handle.hasClass('on'))) {
                        updateState();
                    } else {
                        revert();
                    }
                }
            });
    
            // Set up initial state of the button
            if (input.first().is(':checked')) {
                move('right', 0);
            } else {
                handle.addClass('on');
            }
        });
    
        return this;
    };})(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this class while reading a C# book and have some questions.
Came across this error today. Wondering if anyone can tell me what it means:
I came across this article written by Andrei Alexandrescu and Petru Marginean many years
I came across this recently, up until now I have been happily overriding the
I came across this snippet of code on MSDN: entityBuilder.Metadata = @res://*/AdventureWorksModel.csdl| res://*/AdventureWorksModel.ssdl| res://*/AdventureWorksModel.msl;
Just came across this quote in a book on OOP that I'm reading, A
Just came across this website . Feature 9 is memory management and they claim
I came across this code today AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null); Is there anything wrong with
I came across this article discussing why the double-check locking paradigm is broken in
I came across this answered question , but I can't seem to compile the

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.