jquery - 从左边隐藏/显示

标签 jquery html

我有这个代码可以隐藏/显示。我希望 div 在向左移动时隐藏。我怎样才能做到这一点? This is what I have FIDDLE

JavaScript

$(document).ready(function() {
    $("#button").toggle(function() {
        $(this).text('Show Content');
    }, function() {
        $(this).text('Hide Content');
    }).click(function(){
        $("#hidden_content").slideToggle("slow");
    });
});

HTML

<a href="#" id="button" class="button_style">Hide content</a>
<div id="hidden_content">Content</div>

最佳答案

使用.animate()width 设置为 toggle .

jsFiddle Demo

$("#hidden_content").animate({width: 'toggle'}, "slow");
  • P.S - 注意我添加了一个 CSS 设置,将 #hidden_​​content 的显示更改为 inline-block,因为默认宽度div(block 元素)的比例为 100%,这样动画有点奇怪。

Animation Properties and Values

...

In addition to numeric values, each property can take the strings 'show', 'hide', and 'toggle'. These shortcuts allow for custom hiding and showing animations that take into account the display type of the element. In order to use jQuery's built-in toggle state tracking, the 'toggle' keyword must be consistently given as the value of the property being animated.

关于jquery - 从左边隐藏/显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18887449/

相关文章:

jquery - 如何更改文本区域的占位符?

java - 在基于 id 设置值时对 jsp 行为感到困惑

html - 谁能帮我修复我的CSS?

javascript - YouTube订阅按钮显示错误

html - 导致滚动的宽菜单溢出

javascript - 如何在没有 Controller 的情况下使用 ng-class ?

javascript - iframe-resizer JS 库 : Child Anchor Link Not Working w. iFrame Parent

html - Css 用颜色填充 div 高度

javascript - 禁用 JavaScript 进入表单

javascript - 如何使用开始最小化的 html、css、jquery 和 php 创建响应表单?