Effortless transition of the outer columns gliding in and out on the webpage

My goal is to have the outer two columns smoothly slide out upon refresh, and then slide back when the mouse hovers over the left/right edge.

Here is the fiddle for reference: https://jsfiddle.net/3362xu89/

Below is the jQuery code I am using:

var toggleEdges = function(width) {
                var end = true;
                var slideOutLeftEdge = function() {
                    $('.leftAnchor').animate({width: '0px'}, 1000, function() {
                        $('.leftAnchor').hide();
                        end = true;
                    });
                };
                var slideInLeftEdge = function() {
                    $('.leftAnchor').show();
                    $('.leftAnchor').animate({width: width + 'px'}, 1000, function() {
                        end = true;
                    });
                };
                var slideOutRightEdge = function() {
                    $('.rightAnchor').animate({width: '0px'}, 1000, function() {
                        $('.rightAnchor').hide();
                        end = true;
                    });
                };
                var slideInRightEdge = function() {
                    $('.rightAnchor').show();
                    $('.rightAnchor').animate({width: width + 'px'}, 1000, function() {
                        end = true;
                    });
                };

                slideOutLeftEdge();
                slideOutRightEdge();
                $(document).on('mousemove', function(event) {
                    if (event.pageX > width) {
                        if (end) {
                            end = false;
                            slideOutLeftEdge();
                        }
                    }
                    if (event.pageX < 10) {
                        if (end) {
                            end = false;
                            slideInLeftEdge();
                        }
                    }
                    if (event.pageX < window.innerWidth - width) {
                        if (end) {
                            end = false;
                            slideOutRightEdge();
                        }
                    }
                    if (event.pageX > window.innerWidth - 10) {
                        if (end) {
                            end = false;
                            slideInRightEdge();
                        }
                    }
                });
            };
            toggleEdges(500);

However, this implementation has some issues. It sometimes leaves a 100px wide gap at the end of the animation, the hover effect may not work consistently on the website, and it can struggle or stop working when there is additional JavaScript code running on the site.

Can anyone spot what might be wrong with this setup?

Answer №1

If you're looking to implement something similar, consider the following code snippet:

example.com/7654tyu1/8/

Just a heads up, I'm only giving you part of the solution. How you choose to animate it is up to you.

By the way, remember to clear existing classes before adding new ones.

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

What could be the issue with this piece of Angular code?

Just starting to dive into AngularJS and following a tutorial on YouTube. I've copied the exact code from the instructor, but for some reason it's not working for me. Apologies for the newbie question, but I'm genuinely surprised that the co ...

Executing selenium tests on Internet Explorer 11 on a Windows 10 1809 machine without encountering any new pop-up windows

While testing on my computer, I encountered an issue where my test would start successfully, but after opening and closing several Internet Explorer windows during the test, no new windows would open. There were no error messages displayed, and the test se ...

Issue with callback function not triggering after comment deletion in REACT

Although I am successfully able to delete the comment, I am facing an issue where the callback function is not being invoked. My suspicion is that it might be related to how I pass multiple arguments to the function, but I cannot confirm this. Below is th ...

Exploring the power of for-loops in Reactjs within the componentDidMount lifecycle

I'm struggling to understand why the state of my component fails to update inside a for-loop. Let's look at an example: class Example extends React.Component { constructor() { super() this.state = { labelCounter ...

Adjusting the parent with CSS transitions to perfectly align with the final height of a

Jade example div.parent div.child1 div.child2 Upon initial load, Child1 is visible. Clicking will hide Child1 and make Child2 visible. Another click will reverse this action. During the transition between hiding and showing the children, there s ...

I'm a beginner when it comes to Android WebView and incorporating JavaScript into my projects

Struggling to make my Android app work with JavaScript, even though I've enabled it. Despite all the research I've done suggesting it should work, it's not. Any assistance would be greatly appreciated. Below is my Java code: protected ...

Executing the command causes an error when res.download() is called, resulting in a request

I am currently working on developing an archive that includes various .txt files and then I intend to download this archive. Take a look at the code snippet below: async function archiveAndDownload(res) { const bashCommand = ... const archive = ... ...

What is the best way to assign a numeric variable to the value attribute of an HTML form input?

Is there a way to assign a numeric value to the value attribute of an HTML form input element using a variable? I understand that the value attribute automatically gets converted to a string. How can I make sure the variable is read before being converted? ...

Modifying the default value script to function across various rows

Utilizing a script called jquery.defaultvalue.js, I have added default text to various input fields on a form: <script type='text/javascript'> jQuery(function($) { $("#name, #email, #organisation, #position").defaultvalue("Name", "Emai ...

A Guide on Modifying a Pseudo Element When Clicked

How can I create a click handler in jQuery to change the color of an 'eyebrow' element above a Heading element? The eyebrow element is set up with a pseudo element in my project, and I'm struggling to make it change color when the heading is ...

What is the best way to combine two JavaScript objects?

One object I am currently working with resembles the following structure let ob1 = { 'item_data':{ 'stack':{ 'purchase':'12345', 'order':'22222' } } } Additionally, I have anothe ...

Issues with the PHP mail function are preventing it from working properly, despite client side validation

Having trouble getting three scripts to work together. Specifically, I am trying to make this email function send mails successfully. I have removed any sensitive information and replaced it with generic terms. Additionally, I have another PHP mail functio ...

I am having an issue with uploading multiple files asynchronously to Firebase storage and retrieving their URLs

My issue revolves around uploading multiple files to Firebase storage after adding an image. The upload works fine, but I encounter a problem when trying to retrieve the download URLs for these files. While getting URLs for multiple files is successful, I ...

Jquery Time Picker for AM PM Selection

I have experience using the Jquery date picker (jsfiddle), but now I am interested in creating an AM/PM picker using Jquery. My goal is to have a button that, when clicked, displays the time with the format (12:56:AM) or (01:12:PM). Can anyone provide gu ...

Tips on securing ajax post values against browser inspection techniques

function updateR() { $.ajax({ type: "POST", url: "update.php", data: { surprize: '12345678910', dpoint: point, dlevel: level } }).done(function( msg ) { // alert( "Data Saved: " + msg ); }); ...

Use column formatting for the table's body section

I have written the code below in HTML to create a table. I am looking to apply a specific style to the table body elements in a column that has been assigned a CSS class, while excluding the header columns from this style application. As an example, I hav ...

The contents of the $localStroage array do not align with those of the $scope array

I am storing objects in a `$localStorage` array for persistence. I have a check function to see if an object is already present in the array before adding or removing it (using `splice` if present, and `push` if not). However, after refreshing my page, th ...

Exploring nested JSON objects with Alasql

I am currently working with a JSON object that represents two companies, Ebay and Amazon. For the Ebay Object: { __v: 0 _id: "56e192f0aea7131c15513328" headquarters: "New York" name: "Ebay" productCategories: [{ _id: "56e193be ...

"Discover the best way to sort through an array of complex objects with varying levels of nesting using a specified search

I have come across similar answers, but none of them go beyond two levels deep. Therefore, I believe this is not a duplicate problem. My task is to filter an array of objects where each object may contain nested objects of unknown depth. In my data structu ...

Attempting to minimize the repetition of code in Redux by implementing some utility functions

Is there a potential issue with the method I'm attempting in this URL: The concept involves altering only the actions file when introducing a new action. One improvement I am considering is recursively merging the status passed from the actions with ...