使用JQuery显示更多显示

Wil*_*ran 4 html css jquery

我希望使用JQuery显示更多/更少.我通过谷歌搜索了几个例子,但都没有工作.没什么好看的,我只需要将一段文字剪切到特定的高度,并且链接将扩展/隐藏其他文本.

jon*_*ohn 14

这应该通过单击实际div来切换完整div的显示,您可以将click事件添加到您想要的任何触发器.

HTML:

<div id="blah">
    Long...Content
</div>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

$('#blah').css({height:'20px', overflow:'hidden'});
$('#blah').on('click', function() {
    var $this = $(this);
    if ($this.data('open')) {
        $this.animate({height:'20px'});
        $this.data('open', 0);

    }
    else {
        $this.animate({height:'100%'});
        $this.data('open', 1);
    }
});
Run Code Online (Sandbox Code Playgroud)

最初使用javascript显示较少不会无限期地为没有启用javascript的用户隐藏div.

  • 哈,不是每个人?总是? (5认同)