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

javascript - Jquery slide to visibility hidden? - Stack Overflow

programmeradmin3浏览0评论

I want to achieve something like :

$("#left").hide('slide', {direction: 'right'}, 1000)

However I do not want the div to be hidden I want it to keep up space so I want have the visibility hidden like:

$("#left").css('visibility','hidden')

Yet still achieve the same effect as above.

I want to achieve something like :

$("#left").hide('slide', {direction: 'right'}, 1000)

However I do not want the div to be hidden I want it to keep up space so I want have the visibility hidden like:

$("#left").css('visibility','hidden')

Yet still achieve the same effect as above.

Share Improve this question asked Jan 12, 2012 at 5:34 JonovonoJonovono 3,4255 gold badges46 silver badges65 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 2

This is what I'd do

$parent = $('#left').parent(); //store the parent of the element in a variable
$('#left').clone() //clone the existing element
.appendTo($parent) // insert it into the current position
.css('visibility','hidden') //set it's visibility to hidden
.end().end() //target the initial element
.slideUp() //do any slide/hide/animation that you want here, the clone will always be there, just invisible

This could be horrible, but it's the only way I could think of solving the problem :)

EXAMPLE: http://jsfiddle/skyrim/j2RWt/4

Try this:

var $content = $("#left");
var offset = $content.offset();
$("<div></div>").css({
    width: 0,
    position: "absolute",
    left: offset.left,
    top: offset.top,
    height: $content.outerHeight(),
    backgroundColor: "White"
}).appendTo("body")
.animate({
    width: $content.outerWidth()
}, 1000, function () {
    $content.css('visibility', 'hidden');
    $(this).remove();
});

EDIT

So, after learning what the actual need was (:p), this method basically place another div over the original element. I've tested it on IE...and I'll edit this with an update after I do further testing on other browsers!


EDIT

Only Chrome seems to be having an issue with getting the correct height.


Added a callback which removes the makes visibility hidden (as LEOPiC suggested) and removes the slideout div

You can do it in very simple way. There is really a nice tutorial here to animate in different direction. It will surely help you. try this

$('#left').animate({width: 'toggle'});

EXAMPLE : http://jsfiddle/2p3FK/2/

EDIT: One more solution, this is very simple to move the div out of window with left margin

$("#left").animate({marginLeft:'1000px'},'slow'); 

EXAMPLE : http://jsfiddle/2p3FK/1/

发布评论

评论列表(0)

  1. 暂无评论