最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide a fixed footer? - Stack Overflow

programmeradmin4浏览0评论

Hi I was wondering is there a way to hide a fixed footer with a button, so it can be closed by the user if they want to see more of the screen and vise versa. Is there a way to do this with css or will it require javascript?

cheers.

Hi I was wondering is there a way to hide a fixed footer with a button, so it can be closed by the user if they want to see more of the screen and vise versa. Is there a way to do this with css or will it require javascript?

cheers.

Share Improve this question asked Jan 27, 2013 at 20:20 GibsonFXGibsonFX 1,0602 gold badges13 silver badges36 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 5

JavaScript

<input type="button" id="myButton" onclick="HideFooter()" />

function HideFooter()
{
    var display = document.getElementById("myFooter").style.display;
    if(display=="none")
        document.getElementById("myFooter").style.display="block";
    else
        document.getElementById("myFooter").style.display="none";
}

JQuery

$("#myButton").click(function(){

    if($("#myFooter").is(":visible"))
        $("#myFooter").hide();
    else
        $("#myFooter").show();
});

If you want some other nice effects

$("#myFooter").fadeOut(500);
$("#myFooter").slideUp(500);
$("#myFooter").slideToggle(500); //Hide and Show

Another method, as Bram Vanroy Suggested:

$("#myButton").click(function(){

    $("#myFooter").toggle();
});

It will require JavaScript. Your button click event handler needs to change the display property of the footer to none.

Here's a javascript only version, with the button having and id of "button" and footer id of "footer". This method will allow you to show the footer again after hiding it, if the user wants to see it again.

   var button = document.getElementById('button');

    button.onclick = function() {
        var div = document.getElementById('footer');
    if (div.style.display !== 'none') {
        div.style.display = 'none';
    }
    else {
        div.style.display = 'block';
    }
};

Or with jQuery:

$("#button").click(function() { 
    $("#footer").toggle();
});

A nice tutsplus video tutorial for exactly what you need. It's a simple bit of jQuery.

发布评论

评论列表(0)

  1. 暂无评论