阅读更多链接需要一些小调整

时间:2018-01-25 02:44:07

标签: javascript jquery

我已使用以下代码设置了“Read More”功能,但我希望用户可以选择在完成后关闭展开的文本。所以'少读或'关闭'功能。

我正在使用以下代码:

-- @(#)$Id: random.spl,v 1.2 1997/12/08 19:31:44 johnl Exp $
--
-- Simple emulation of SRAND and RAND in SPL
-- Using random number generator suggested by C standard (ISO 9899:1990)

CREATE PROCEDURE sp_setseed(n INTEGER)
    DEFINE GLOBAL seed DECIMAL(10) DEFAULT 1;
    LET seed = n;
END PROCEDURE;

CREATE PROCEDURE sp_random() RETURNING INTEGER;
    DEFINE GLOBAL seed DECIMAL(10) DEFAULT 1;
    DEFINE d DECIMAL(20,0);
    LET d = (seed * 1103515245) + 12345;
    -- MOD function does not handle 20-digit values...  Dammit!!
    LET seed = d - 4294967296 * TRUNC(d / 4294967296);
    RETURN MOD(TRUNC(seed / 65536), 32768);
END PROCEDURE;

以下是一个实例:http://www.cubadupa.co.nz/?post_type=marcato_artist

有什么想法吗?我是javscript的新手,很抱歉,如果这是一个简单的修复。

1 个答案:

答案 0 :(得分:0)

您可以添加和删除一个类(我选择了.extended)。与扩展元素以缩小元素所需的相反。我选择了200px。根据需要调整。我还调整了您的原始点击事件,以便在包含.extended课程时不适用。

    var $el, $ps, $up, totalHeight;

    // Click handler to extend a minimized element
    $(".sidebar-box").on("click", ".button:not(.extended)", function() {

        // IE 7 doesn't even get this far. I didn't feel like dicking with it.

        totalHeight = 0

        $el = $(this);
        $p  = $el.parent();
        $up = $p.parent();
        $ps = $up.find("p:not('.read-more')");

        // measure how tall inside should be by adding together heights of all inside paragraphs (except read-more paragraph)
        $ps.each(function() {
            totalHeight += $(this).outerHeight();
            // FAIL totalHeight += $(this).css("margin-bottom");
        });

        $up
            .css({
            // Set height to prevent instant jumpdown when max height is removed
            "height": $up.height(),
            "max-height": 9999
        })

            .animate({
            "height": totalHeight
        },500,function(){
            //Callback - after the animation is over
            jQuery('#masonry-content').masonry();
        });

        // Toggle extended class
        $p.toggleClass('extended');

        // update text
        $p.text('Read Less');

        // prevent jump-down
        return false;

    });

    // click handler for minimizing an extended button
    $(".sidebar-box").on("click", ".button.extended", function() {

            // IE 7 doesn't even get this far. I didn't feel like dicking with it.

            $el = $(this);
            $p  = $el.parent();
            $up = $p.parent();
            $ps = $up.find("p:not('.read-more')");

            $up
                .css({
                // Set height to prevent instant jumpdown when max height is removed
                "height": 200,
                "max-height": 200
            })

                .animate({
                "height": 200
            },500,function(){
                //Callback - after the animation is over
                jQuery('#masonry-content').masonry();
            });



            // Toggle extended class
            $p.toggleClass('extended');

            // update text
            $p.text('Read More');

            // prevent jump-down
            return false;

        });