【问题标题】:jquery hide/show functionjquery隐藏/显示功能
【发布时间】:2013-03-20 22:02:36
【问题描述】:

嗨!我只是 jquery 函数的新手,我能够完成某些 div 的隐藏/显示功能,但我想在执行显示 div 时以居中的方式制作。现在这些 div 有内容但是当我点击显示它从左到右出现..有人可以做这些技巧来居中吗?

window.onload = function(){
    $('#show').click(function()
    {
        $('#nav').show('blind');
        $('#show').hide();
        $('#hide').show();
    });

    $('#hide').click(function()
    {
        $('#nav').hide('blind');
        $('#hide').hide();
        $('#show').show();
    });
}

【问题讨论】:

  • 请提供HTML和CSS代码

标签: jquery centering


【解决方案1】:

使用 .toggle() 同时进行隐藏和显示。你不需要单独编写显示和隐藏函数

http://api.jquery.com/toggle/

<!DOCTYPE html>
<html>
<head>
<style>
p { background:#dad;
font-weight:bold;
font-size:16px; }
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<button>Toggle 'em</button>
<p>Hiya</p>
<p>Such interesting text, eh?</p>
<script>
$("button").click(function () {
$("p").toggle("slow");
});
</script>
</body>
</html>

【讨论】:

  • 我明白了,但我想知道是否有可能在中心获得演示(从隐藏的参考到显示状态),而不是从左到右执行点击切换按钮?。
  • 如果您想从中心弹出类似演示文稿,请参阅此链接jqueryui.com/toggle
猜你喜欢
  • 2012-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
相关资源
最近更新 更多