Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic positioning of the Tool Tip (Tooltip) #432

Closed
Bilal-Abdeen opened this issue Apr 14, 2015 · 2 comments
Closed

Dynamic positioning of the Tool Tip (Tooltip) #432

Bilal-Abdeen opened this issue Apr 14, 2015 · 2 comments

Comments

@Bilal-Abdeen
Copy link

Hi,

This is a very good plug-in. Thank you so much.

I wonder if there is a way to make the tool tips change position dynamically (CSS left attribute), depending on the position of the sliding button at the sliding bar?

When it is at the right edge, it should be right-aligned with the bar right end. When it is at the left edge, it should be left-aligned with the the bar left end. When it is in the middle, the tool tip should be center-aligned with the sliding button.

If there a simple tweak to the JS code, I would appreciate knowing about it.

Thanks
Bilal

@eskimoblood
Copy link

I've had the same problem, this is my solution:

updateSliderTooltip: function(slider, value) {
        var left = slider.find('.noUi-origin').position().left;
        var width = slider.width();
        var tooltip = slider.find('.btn');
        if (left < 60) {
          tooltip.css('left', -left + 'px');
        } else if (left > width - 60) {
          tooltip.css('left', (width - left - 120) + 'px');
        } else {
          tooltip.css('left', '');
        }

        tooltip.html(templateStrings.templates.settings.freepages.slider.free + ' ' + parseInt(value, 10) + 'PIs');
      },

      createSlider: function(type) {
        var slider = $('#' + type + 'Slider').noUiSlider({
          start: 0,
          connect: 'lower',
          step: 1,
          range: {
            'min': 0,
            'max': 100
          }
        });

        slider.on('slide', _.bind(this.updateSlider, this, type, slider));
        slider.Link('lower').to('-inline-<div class="btn btn-primary"></div>', function(value) {
          this.updateSliderTooltip(slider, value);
        }.bind(this));
}

The only problem is that the function is only called when the slider is dragged, not when you click somewhere on the slider. In this case its only called once with the start position.

@github-actions
Copy link

github-actions bot commented Jun 5, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants