Animate custom scrollbars with jQuery for a unique browsing experience

I am experimenting with creating a scrolling animation using mCustomScrollbar

Currently, I have managed to obtain the current scrollTop and animate it to a specific height using the code below:

$("#content").mCustomScrollbar({
    scrollButtons:{
        enable:true
    },
        advanced:{
            updateOnContentResize: true,
            updateOnBrowserResize: true,
    },
    callbacks:{
        onScrollStart:function(){ onScrollStart(); },
        whileScrolling:function(){ WhileScrolling(); } 
    }
});

function WhileScrolling(){
    var top = Math.abs(mcs.top);

    if(top > 180){
        $('#topbar').animate({opacity:'0'});
    }

However, when I attempt to reverse the animation with the following code:

if(top < 180){
    $('#topbar').animate({opacity:'1'});
}

This section fails, and once included, the animate({opacity:0}) seems to have a delayed start before initiating the animation.

Here is a preview:

Answer №1

If you encounter any issues with #topbar animations, make sure to pause them before using the .animate() function:

$('#topbar').stop().animate({opacity:'1'});
$('#topbar').stop().animate({opacity:'0'});

For more information on how to use jQuery .stop(), check out the documentation at: http://api.jquery.com/stop/

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

Adding a Table Row in jQuery without Appending it to the Bottom of the Table

I am working on a project that involves an HTML Table where the user can add a new Row by clicking a button. However, I want the new Row to be added not at the end of the table, but after the last row of input fields. To demonstrate, I have prepared a sam ...

Compel instantaneous XMLHttpRequest / Ajax without any prior notification

It's no secret that synchronous XMLHttpRequest has been deprecated due to its negative impact on user experience. The deprecation of Synchronous XMLHttpRequest on the main thread is a result of its adverse effects on end users' experience. For ...

I am looking to build an array that can store five numbers inputted by the user. Following that, I want to utilize a for loop to display the contents of the array. How can I accomplish this task?

Looking for help to store 5 unknown numbers in an array and then display them after the user has entered all 5 numbers. Can anyone assist me in creating an array of size 5 and using a for loop to show the numbers? Here is the code I currently have: ...

The v-bind class feature is failing to update the CSS on the object's properties

I'm attempting to dynamically modify the CSS of certain buttons based on object properties within a list. Below is the data I am rendering out, and despite following the documentation and ensuring my setup is correct, I seem to be overlooking somethin ...

Styling div elements within other div elements using CSS

I am currently working on creating a layout with three divs, each containing an image. The challenge is to set the height of the first div (top) to 10% of the screen size, the second (middle) to 60%, and the third (bottom) to 30%. I want these divs to main ...

Changing the size of circles in text and adjusting the dimensions of SVG elements

As a novice JavaScript programmer, I am attempting to resize circles and SVG elements based on the window size. Currently, my code creates circles of varying sizes, but I haven't been able to adjust them in relation to text size. var width = 600; va ...

Firefox won't trigger the `beforeunload` event unless I interact with the webpage by clicking on it

In my quest to handle the beforeunload event in Firefox, I've encountered a small hurdle. It seems to be working smoothly, but only if the user physically interacts with the page by clicking on it or entering text into an input field. Below is the co ...

Styling Process Steps in CSS

Just starting out with CSS! I'm looking to replicate the Process Step design shown in the image. https://i.stack.imgur.com/Cq0jY.png Here's the code I've experimented with so far: .inline-div{ padding: 1rem; border: 0.04rem gray ...

Success/Fail Page for Form Redirect

I've been struggling to figure out how to redirect my form to a success or fail page. I've scoured the internet for solutions, looking into traditional form redirects and even JavaScript onClick redirects. Can someone guide me on adding a redirec ...

Unable to save the ID of an element into a jQuery variable

I am currently working on a project that involves an unordered list with anchor tags within it. I am trying to access the id of the li element that is being hovered over, but for some reason, the alert is returning undefined or nothing at all. Here is the ...

A helpful guide on displaying validation errors in a form using React JS

After creating a form and connecting it to the server, I encountered an issue with displaying validation errors below respective input fields. The error message response in case of validation error is as follows: "message": "ValidationError: confirmPasswor ...

Exploring the fnServerData function in DataTables

I have integrated Datatables into my project and I am really interested in the "fnServerData" callback option. After reviewing the documentation Here, I came across the example code below: $(document).ready( function() { $('#example').dataTabl ...

trigger the focusout event within the focusin event

I am attempting to trigger the focusout event within the focusin event because I need to access the previous value from the focusin event, but the focusout event is being triggered multiple times. $('tr #edituser').focusin(function(){ var ...

Customized height for vertical Slick slider based on content length

I am facing an issue with my vertical slick slider: $('.slider').slick({ slidesToShow: 3, slidesToScroll: 1, arrows: false, dots: false, infinite: false, centerMode: true, vertical: true, focusOnSelect: true }); .slider { bac ...

Incorporating jQuery to convert text into clickable links

Here is the situation: <div class="myclass"> Lorem ipsum dolor sit amet, http://example.com consectetuer adipiscing elit. </div> I am looking for a jQuery function that can be executed after the dom ready event. This function should locat ...

What is the process of adding CSS effects to a button when a keypress activates it?

Do you have a CSS style that transforms the look of a button when clicked on-page? Want to extend this effect to when the button is activated via keyboard? (In essence, browsers allow activating a button by pressing Tab to give it focus and then hitting S ...

What causes Google fonts to fail on Heroku but succeed when used locally?

I am currently using express and heroku to host a prototype of a landing page. While the webpage functions properly when running locally, I encounter font loading issues when accessing it on heroku most of the time... The CSS files are located under /pub ...

Passing PHP array to JavaScript in a specific format

After running the code provided, I find that the data returned is in an array format but unfortunately not easily referenced. AJAX: $.ajax({ url: './FILE.php', type: 'post', data: {'action': 'allfolders'}, ...

Including a JavaScript file in an HTML document initiates a server request, which can lead to potential errors

I am currently developing a web application using Express and Node.js on the backend, with EJS as the templating engine on the frontend. Here is a snippet of my app.js file: app.get('/book/:id', (req, res)=>{ var book_id = req.params.id; cons ...

Passing a value from a prop to a click event that is dynamically created within an SVG Vue.js

Currently, I am in the process of developing a map component using a JSON array and implementing a click event handler for each item. The objective is to toggle the CSS style to color the item when clicked, which is functioning as expected. However, my goa ...