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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:17:40+00:00 2026-05-21T15:17:40+00:00

as you may already know I’m new to jQuery, so Code-Improvements not belonging to

  • 0

as you may already know I’m new to jQuery, so Code-Improvements not belonging to this theme are still very allowed.

This is my HTML-Code:

<div style="display: inline-block; width: 120px;">
    <div>
        Bananas:
        <br />
        <input id="bananas_amount" />
        <input id="bananas_amount_percent" />
    </div>
    <br />
    <div id="bananas" style="height:200px;"></div>
</div>

And this is my horrifying js-code:

$( "#bananas" ).slider({
    orientation: "vertical",
    range: "min",
    min: 0,
    max: 100,
    value: 20,
    step: 5,
    slide: function( event, ui ) {
        $( "#bananas_amount_percent" ).val( ui.value + " %" );

            // the code displays a percentage by standart, but I need the real value, too:
            var bananas_amount_percent = $( "#bananas_amount_percent" ).val();
            var bananas_amount_percent = bananas_amount_percent.replace(" %", "");
            var bananas_amount = Math.round((weight / 100) * bananas_amount_percent);
            $( "#bananas_amount" ).val( bananas_amount + " g" );
    }
});
$( "#bananas_amount_percent" ).val( $( "#bananas" ).slider( "value" ) + " %" );

// again the real value (else the value would not be updatet on reload-reset)
var bananas_amount_percent = $( "#bananas_amount_percent" ).val();
var bananas_amount_percent = bananas_amount_percent.replace(" %", "");
var bananas_amount = Math.round((weight / 100) * bananas_amount_percent);
$( "#bananas_amount" ).val( bananas_amount + " g" );

(weight is 200)

However, it’s working, except one “little” detail: not with the mousewheel!
I already found out that I need this extension: https://github.com/brandonaaron/jquery-mousewheel/downloads

But I’ve really absolutely no idea how to implement this to my Slider (I’ve 5 on my Site btw).

Help pls,
Thx!

  • 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-21T15:17:40+00:00Added an answer on May 21, 2026 at 3:17 pm

    The mousewheel plugin is too heavy for its role. I extracted the essence. Works great in all browsers.

    $('#bananas').bind('mousewheel DOMMouseScroll', function (e) {
        var delta = 0, element = $(this), value, result, oe;
        oe = e.originalEvent; // for jQuery >=1.7
        value = element.slider('value');
    
        if (oe.wheelDelta) {
            delta = -oe.wheelDelta;
        }
        if (oe.detail) {
            delta = oe.detail * 40;
        }
    
        value -= delta / 8;
        if (value > 100) {
            value = 100;
        }
        if (value < 0) {
            value = 0;
        }
    
        result = element.slider('option', 'slide').call(element, e, { value: value });
        if (result !== false) {
            element.slider('value', value);
        }
        return false;
    });
    

    EDIT: changed #slider to #bananas

    EDIT2: added triggering slide event

    Because you are using only value property I pass for parameter object with only this property. If you will need something more, remember to add it to the mousewheel code.

    EDIT3: added change cancelling ability when slide function returns false (just like in the documentation)

    UPDATE: delta shows not only the wheel direction, but also has a deeper meaning. It describes number of pixels to scroll. The default setting for scrolling is 3 lines which is 120 pixels, but it can differ.
    If you want to retrieve only direction of wheel, change this:

    value -= delta / 8;
    

    to this:

    value -= (delta > 0) ? 5 : (delta < 0) ? -5 : 0;
    

    although delta === 0 should never occur.

    UPDATE: Added part for newer versions of jQuery (e.originalEvent).

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

Sidebar

Related Questions

I have a feeling I may already know the answer to this question, but
I think I may already know the answer to this, but here goes. I
I may already know the answer to this question, but I thought it was
C or C++ preferred. This is not an Objective-C project. I already know the
As you may already know, the .NET Framework's protected internal access modifier works in
As many of you may already know I have been having issues with another
May be some body already used some open source component, writing on jquery. And
This may well be a dumb question and if this has already been answered
may i know how to use this getMicrophone with simpleFLVWriter to create flv with
So as many of you may already know, CommonCrypto isn't included in the iPhone

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.