Jquery滑动到可见性隐藏?

发布于 2024-12-26 21:01:57 字数 229 浏览 0 评论 0原文

我想要实现类似的目标:

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

但是我不希望隐藏 div,我希望它保留空间,所以我希望隐藏可见性,例如:

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

但仍然达到与上面相同的效果。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉生梦死 2025-01-02 21:01:57

这就是我要做的

$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 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 :)

萌梦深 2025-01-02 21:01:57

示例: http://jsfiddle.net/skyrim/j2RWt/4

试试这个:

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();
});

编辑

所以,在了解实际需求是什么(:p)之后,此方法基本上将另一个 div 放置在原始元素上。我已经在 IE 上进行了测试...在其他浏览器上进行进一步测试后,我将通过更新来编辑它!


编辑

只有 Chrome 似乎在获得正确的高度方面存在问题。


添加了一个回调,该回调删除隐藏可见性(如 LEOPiC 建议)并删除滑出 div

EXAMPLE: http://jsfiddle.net/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

风蛊 2025-01-02 21:01:57

您可以用非常简单的方式做到这一点。 这里确实有一个很好的教程< /strong> 以不同方向制作动画。它一定会对你有所帮助。试试这个

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

例子: http://jsfiddle.net/2p3FK/2/

编辑:< /strong> 另一种解决方案,这非常简单,可以将 div 移出窗口并使用左边距

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

示例:http://jsfiddle.net/2p3FK/1/

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.net/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.net/2p3FK/1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文