Enhance your website with footer animations using jQuery!

I am implementing a sticky footer on my website to keep the footer at the bottom using CSS. I want the footer to initially be collapsed and expand when the user clicks on a button, swapping the "expand" link with a different container div inside the footer.

How can I achieve this using jQuery, HTML, and CSS?

UPDATE:

Initially, I want the footer to have a height of 20px. Inside the footer, there should be a button (or link) that says "more" or "about". When clicked, the footer will expand to reveal a more detailed div with alternate content instead of the "more" link.

Answer №1

Take a look at this jsFiddle to see a demonstration of the slide-in technique.

Here is a breakdown of what you will discover in the above link:

  1. Create your css so that the initial footer height is set to 0. Ensure to also adjust other css values related to footer height such as padding-bottom on #main and margin-top on #footer. Additionally, remember to apply overflow:hidden on #footer to hide the content when collapsed.

  2. In the click() function for your link, use jQuery's animate() method to increase the height of #footer (along with necessary padding/margin adjustments).

  3. The animate() function has four parameters (see documentation), with the last one being a callback function that executes once the animation is complete. You can perform your link swapping within this callback function.

If you are starting with the HTML/CSS from CSSStickyFooter, the remaining code would appear as follows...

Your CSS (this must be placed after the stickyfooter css):

#main { 
    padding-bottom: 0; 
}  
#footer { 
    margin-top: 0;
    height: 0; 
    overflow:hidden;
} 

And your Javascript should resemble this:

$(document).ready(function(){
    $('#showFooter').click(function(evt) {
        $('#footer').animate({
            'margin-top' : -150,
            'height' : 150
        }, null, null, function() {
            alert("footer slide-in is complete.");
            // Implement your "link swap" operation here. 
        });
        $('#main').animate({
            'padding-bottom' : 150
        });
    });
});

Edit: If you wish to have the footer initially visible (at a smaller size) and then expand to a larger size, simply set any desired height (instead of 0) in the provided CSS code.

You can insert any preferred content into the footer div -- if you want to display different sets of content when it's small versus large, place these blocks into two separate divs within the footer. Set them as position:absolute;top:0; so they overlap within the footer. Initially, set the "expanded view" to display:none and later utilize jQuery's fadeIn() and fadeOut() functions within the click handler or animate callback to toggle visibility between the expanded and collapsed views within the footer.

Check out this adjusted jsFiddle example


For a more sophisticated approach, consider making the footer heights dependent on the content views. (This might be a preferable option).

View this "fancier" jsFiddle calculating heights based on content


Edit: To enhance smoothness and prevent flashing scrollbar during the animation, switch the order of the two animate calls (placing $('#main').animate(...) before $('#footer').animate(...)). This adjustment ensures better animation flow without flickering scrollbars. See the updated jsFiddle demonstrating this change.

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

Is it true that AngularJS is unable to update data attributes?

I'm working with an input element that utilizes the type-ahead plugin from bootstrap. My goal is to dynamically set the data-source attribute as the user types, creating a real-time search effect. <input id="test" data-provide="typeahead" data-sou ...

Bug in ZURB Foundation Topbar causes incorrect highlighting of links on mobile when clicked

While utilizing the ZURB Foundation Topbar, I have encountered a bug that I find frustrating. When navigating the 2nd level drop downs and clicking on a link (li elements), the active highlight flickers to one of the elements above before taking you to the ...

What is the method for an (angular) custom element to determine if a <slot> tag has been utilized?

I'm working with a custom element that has multiple named slots. Based on a certain state, one of the slots will be displayed. Here is an example of how the custom elements are structured: <slot></slot> <slot name="small"></slot& ...

Tips for dynamically adding an HTML element to index.html using JavaScript

How can I use JavaScript to insert cards into a container or display them in flex? Currently, the cards are not displaying as desired. I attempted to insert data into the note class using insertAdjacentHTML in JavaScript, but struggled to place them in the ...

What could be causing the issue of CSS Styles not being applied to an Angular 2 component with Vaadin elements?

Currently, I am immersed in the tutorial on Vaadin elements using Angular 2 that I stumbled upon here In section 5.3, Styles are applied to the app.component.ts as shown below import { Component } from [email protected]/core'; @Component({ select ...

What could be the reason that data-bs-placement="right" is not functioning as expected?

I am facing an issue with the popover functionality in my project. No matter what value I set for data-bs-placement attribute, it does not display correctly. Can you help me understand why this is happening? <!DOCTYPE html> <html lang="en ...

Using -webkit-transform with varying transition durations for rotateX and rotateY properties

Is it possible to have different transition times for both rotateX and rotateY in CSS3? I know you can use -webkit-transition to set a time, but it seems like setting separate transition times for both is not doable. It appears that you can only set it for ...

The missing piece of the puzzle that eludes me - implementing jQuery hover with Sidr

Introducing Sidr, a revolutionary plugin that transforms ordinary sidebars into sleek additions to your webpage. In my quest for customization, I endeavored to craft a bespoke button that would seamlessly toggle the sidebar's display. Enter the #hove ...

Incorporate a background image property using Jquery

Can anyone help me with adding the css background-image:url("xxxxx") property to my code? jQuery('#'+$trackID+' .sc_thumb').attr('src',$thumb_url); jQuery('#'+$trackID+' .sc_container').css('display& ...

Trouble with implementing web methods through AJAX communication channel

my .cs code is auth_reg.aspx.cs (breakpoint shows the method is never reached) [WebMethod] public void ImageButton1_Click() { string strScript = "<script language='JavaScript'>alert('working')</script>"; Page.Regis ...

Using the Slim framework to communicate through JSON

When attempting a simple POST request, I am having trouble reading the JSON data no matter what I try. $.ajax({ url: 'server/account/session', type: 'POST', data: { "username": name, "password": password} , ...

Managing an iframes website using buttons and links: Tips and tricks

I am trying to create a website that includes an iframe for navigating through external websites using previous and next buttons. I also want to display the links on a sidebar so that users can click on them to automatically load the site in the iframe. I ...

Utilize JavaScript and jQuery to extract the selected text's context from a webpage

I'm looking to extract the contextual information surrounding a selected text on a web page, specifically the 25 words before and after it. I've tried using JavaScript and jQuery with the following code snippet but unfortunately, it doesn't ...

"Enhance User Experience with a Dynamic AutoComplete Feature in jQuery TextBox

On my ASP.Net page, I have two AutoCompleteTextBoxes that need to interact in a client-side way. The goal is for the second textbox to receive the value from the first box and use it as one of the options for displaying the list. $("#txtBox1").AutoComple ...

Efficiently Updating Multiple Highcharts Charts Using a Single Function

I have 4 different charts displayed on this page. <div id="section"> <div id="all" style="min-width: 400px; height: 400px; margin: 0 auto"></div> <div id="top10" style="min-width: 400px; height: 400px; margin: 0 auto">< ...

Every time I input information into the form, it keeps coming back as undefined

function displayProduct() { var product = document.getElementById("productForm"); var item = product.elements["item"].value ; document.getElementById("outputResult").innerHTML = item ; } <div> <p id="outputResult"></p> </di ...

Guide on stacking a transformed 3D div on top of a masked layer with higher Z-index without success

I am attempting to stack a green div on top of a blue div using CSS transformations. The blue div acts as a masked layer, while the green div is a dialog that should appear on top. I have tried adjusting the z-index property, but the blue div always ends ...

The outcome of a function within the $.ajax method is transformed into a string

Trying to pass an array of IDs using the $.ajax data variable is proving to be a challenge. The array is generated by a function, and I've noticed that if I define this function outside of the $.ajax call, it works fine. However, when I place the same ...

Avoid duplicate submissions while still enforcing mandatory fields

Let's start with a basic form that only asks for an email address: <form action="NextPage.php" method="post"> <input type="email" name="contact[email]" required id="frmEmailA" autocomplete="email"> <button type="submit">Subm ...

Tips for organizing JSON data from a multiselect form

I am currently working on a template driven form with a multiselect field named assets. My framework of choice is semantic UI. <div ngModelGroup="assets"> <div class="field"> <label for="resourceName">Assets</label ...