Creating a “read more” link that extends the content on the page

后端 未结 10 2144
萌比男神i
萌比男神i 2021-01-03 06:06

I would like to create a read more link that would extend a paragraph already being shown to reveal the entire text on the same page. If this could be solves with HTML5 and

10条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-03 06:44

    I've created a jQuery/JS script that should do the trick: JSFiddle: http://jsfiddle.net/Starfire1337/pL9ve/

    HTML:

    
     // Notice the custom JS is included AFTER jQuery
    

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor feugiat ipsum quis ullamcorper. Nullam vitae velit vitae tortor semper tempor ac vitae magna. Maecenas a ullamcorper neque. Aliquam vitae tortor luctus nisi rutrum eleifend non non leo.

    Read More...

    and in /js/site.js:

    $(document).ready(function () {
        $('.nav-toggle').click(function () {
            var collapse_content_selector = $(this).attr('href');
            var toggle_switch = $(this);
            $(collapse_content_selector).toggle(function () {
                if ($(this).css('display') == 'none') {
                    toggle_switch.html('Show');
                } else {
                    toggle_switch.html('Hide');
                }
            });
        });
    
    });
    

提交回复
热议问题