Using the .slider class on concealed div elements

Explaining this may be a bit tricky, but here we go... I have multiple hidden divs that switch with each other when a link is clicked using

$(document).ready(function(){
  $('a').click(function () {
    var divname= this.name;
    $("#"+divname).show("slow").siblings().hide("slow");
  });
});

I also have a slider function that works perfectly. However, when the div changes, the slider stops working. How can I make it target the hidden divs when they are displayed? Is it related to variables?

This is my slider code:

$(function() {
var scrollPane = $('#info'),
    scrollableHeight = scrollPane.height() - scrollPane.parent().height() || 0;

$("#slider-vertical").slider({
  orientation: "vertical",
  range: "max",
  min: 0,
  max: scrollableHeight,
  value: scrollableHeight,
  slide: function(event, ui) {
    scrollPane.css({top: ui.value - scrollableHeight});
  }
});

});

To better understand, here is a link to a working example (please excuse the messy code):

Thank you in advance.

Answer №1

To ensure that all your sliding divs are included in the scroll functionality along with #info, it is recommended to assign them a shared class like class="info". Modify the code snippet as follows:

var scrollPane = $('.info'),
    scrollableHeight = scrollPane.height() - scrollPane.parent().height() || 0;

Additionally, remember to reset the slider to its default position when showing or hiding any of the divs:

$(document).ready(function(){
  $('a').click(function () {
    var divname= this.name;
    $("#"+divname).show("slow").siblings().hide("slow");

    // Reset slider to top
    var max = $("#slider-vertical").slider("option", "max);
    $("#slider-vertical").slider("value", max);
  });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The effectiveness of border-radius is limited to only one side of the div

After experimenting with applying the border-radius property to a div, I encountered an issue where the border radius only worked on one side when the radius value was too large. How can I resolve this problem while maintaining the border-radius value on a ...

Using Javascript to create a radio button group

Is there a way to trigger an alert message when all radio buttons are checked as 'no'? I currently am only able to check each radio button individually. //The method I currently know $('#attraction1').change( function(){ if ($(this ...

Using jQuery AJAX to preload GIF images for CSS background-image loading

For some time, I have been utilizing jQuery AJAX to preload GIF images with the following code: $("#images").html("<img id='loader' src='../img/ajax-loader.gif' />"); Now, I am attempting to achieve a similar effect (such as a s ...

jQuery script for reversing the collapse/expand feature

Here is a test showcasing an expand/collapse jQuery script. Currently, the div is collapsed on page load and you need to click it to see the content. Is there a way to change this so that the div is expanded on load and collapses upon clicking? <style ...

Show the content of a list from a different URL on a webpage using HTML with the

My current task involves retrieving JSON data using Jquery and then displaying the names in a simple HTML list. Typically, the JSON files I work with have a straightforward format like: [ {a:1,b:2},{a:3,b:4}] However, this time, the JSON file is hosted ...

I have been struggling to get AJAX to work properly with Load and selector, but no matter what I try, the scripts just won

Yesterday, with the assistance provided here, I discovered how to load AJAX'ed content and maintain the page structure. However, I encountered an issue where the script tags were not loading. Upon further investigation, it appears that when using a se ...

trouble with padding on cards using vue-bootstrap

I have been working on creating a card component with Vue Bootstrap, but I've run into an issue. The card header and body seem to have excessive padding around them. If I remove the b-card element and only use b-card-header and b-card-body, it looks l ...

When checking if el.text() is equal to "string", it will return false, regardless of the actual content of the element being "string"

Looking at the code snippet below, it seems that the else block is always being executed instead of the if block. The alert confirms that the variable state has the value 'payment' as expected. var state = $('.check-state').text(); ale ...

Tips for adjusting column positions in a table while maintaining a fixed header and utilizing both horizontal and vertical scrolling

Is there a way to display a table that scrolls both horizontally and vertically, with the header moving horizontally but not vertically while the body moves in both directions? I have been able to shift the position of the columns, however, I am struggling ...

Connection between modal dialogue and calling function

I currently have a collection of images, each with an attached delete button. Upon clicking the delete button, I trigger a confirmation popup using Twitter Bootstrap modal and jQuery event handling. My main concern now is how to pass a value back to the ...

Arranging elements on a webpage using Javascript

Creating a Dynamic Div Layout with JavaScript I have successfully implemented functionality wherein clicking on + opens a div and clicking on - closes it. However, I am now faced with the challenge of handling multiple divs at runtime. How can this be ach ...

Cease the ongoing Ajax request and switch to a new Ajax call immediately

Within this code snippet, I am capturing user input for typing and then searching it in a database. However, with each character entered by the user, a new AJAX request is triggered without canceling the previous one. My objective is to have the search fu ...

The input field is failing to show up on the screen

I have been working on my React app and experimenting with how to dynamically display input elements based on different screen sizes. To achieve this, I implemented the use of window.innerWidth as shown in the code snippet below: <div className='Tr ...

Determine if the input text field contains any text and store it in a variable using jQuery

I'm working on a form that includes radiobuttons and textfields. To keep track of the number of checked radiobuttons, I use this code: var $answeredRadiobuttons = $questions.find("input:radio:checked").length; But how do I store the number of textf ...

Tips on formatting text as bold or italic when tweeting from my website to our Twitter account

Currently, I am utilizing the Twitter OAuth library in conjunction with PHP to publish a tweet from my website directly to my Twitter account. My main objective is to highlight some text while posting, however, I have not been successful in identifying t ...

Adjusting the opacity of a div while scrolling

I've searched multiple pages, but haven't found a solution that works for me. I'm trying to make the text in my div gradually become more transparent as I scroll. Can anyone help with this? Here's my code: <script src = "/js/titleSc ...

Exploring ways to incorporate mouse movements into this simple JavaScript script

I have recently decided to convert my JavaScript code into jQuery code to incorporate mouse events. After downloading the latest version of jQuery and renaming it as "jquery.js," I made modifications to my manifest.json file by adding "jquery.js." However, ...

Efficient Pagination in CakePHP Using Ajax Search Functionality with POST Data

I am in the process of implementing a search functionality in my CakePHP 2.x project. Below is the controller code I have written: public function admin_index() { $this->Customer->recursive = 0; $this->Paginator->settings = array( ...

Issue with $.ajax request even when valid JSON data is provided

Below is the code I am currently using: var jsonURL = "http://www.sodexo.fi/ruokalistat/output/daily_json/440/2013/10/25/fi"; var request = $.ajax({ url: jsonURL, dataType: "json", type: "GET" }); request.done(functio ...

Two adjacent divs positioned next to each other, where the right-hand div occupies the remaining space within its

I am facing a common issue with two side-by-side divs, which I usually solve without any problems by floating both divs left and adding a clear:both div after them. However, my requirements have made this problem more complicated to solve... What I would ...