简体   繁体   English

使用CSS块显示/隐藏文本

[英]Showing/Hiding text with css blocks

I'm adding a small section to some community software (IPBoard). 我在一些社区软件(IPBoard)中添加了一小部分。 As shown in the picture below, they have a small triangle icon that triggers the display/hide of a css block.The link text to the right of the triangle icon hyperlinks to another URL. 如下图所示,它们有一个小的三角形图标,可触发css块的显示/隐藏。三角形图标右侧的链接文本将超链接到另一个URL。 Only the triangle icon shows the css block. 只有三角形图标显示css块。 Easy enough. 很简单。

三角形展开文字

For the small section I am adding (see picture below), I want the triangle icon and the link to expand the text for this section (not have the link go to another url). 对于我要添加的小部分(请参见下图),我想使用三角形图标链接来扩展此部分的文本(不使链接转到另一个URL)。 I've made hundreds of other modifications and can generally figure out CSS and basic php is no problem. 我进行了数百次其他修改,通常可以弄清楚CSS和基本php是没有问题的。 But this collapsing and expanding text is really stumping me, after hours of trying. 但是经过数小时的尝试,这种折叠和扩展的文字确实让我感到困扰。 I know there's other ways to do this, but I'd like to leverage their existing technique rather than loading more code, if I can. 我知道还有其他方法可以做到这一点,但我想利用他们现有的技术,而不是加载更多的代码。

我需要的

Here's my HTML code: 这是我的HTML代码:

echo "<ul id='idm_categories'>";
    echo "<li class='with_sub closed'>";

        echo "<a href='#' id='not sure what would go here'>Scripture</a>";

            //Begin Hidden text that will display
            echo "<ul class='subforums' style='display: none'>";
                echo "<li><a href='http://link here' title='Go to category'>Pentateuch (Gen-Deu)</a></li>";


            echo "</ul>";
            //End hidden text


            //This makes the show/hide text possible but not sure how it works...
            echo "<a href='#' class='cat_toggle'>Toggle</a>";

        echo "</li>";

echo "</ul>";

The HTML references CSS. HTML引用CSS。 Here the relevant portion of that is: 这里的相关部分是:

#idm_categories a.cat_toggle {
    text-indent: -2000em;
    width: 12px;
    height: 12px;
    position: absolute;
    left: 8px;
    top: 11px;
    padding: 0;
}

    #idm_categories > li.with_sub.closed > a.cat_toggle {
        background: url({style_images_url}/folder_closed.png ) no-repeat;
    }

    #idm_categories > li.with_sub.open > a.cat_toggle {
        background: url({style_images_url}/folder_open.png ) no-repeat;
    }

    #idm_categories > li {
        /*border-bottom: 1px solid #f3f3f3;*/
        position: relative;
        padding: 0px;
    }

        #idm_categories > li:last-child {
            border: 0;
        }

        #idm_categories > li > a {
            display: block;
            padding: 10px 10px 5px 25px;
        }

        #idm_categories > li.selected > a {
            font-weight: bold;
            background: #4B76AD;
            color: #fff;
        }

    #idm_categories .file_count {
        font-size: 9px;
        padding: 1px 3px;
        font-weight: bold;
        color: #528F6C;
        background: #DFEBF7;
        -moz-border-radius: 3px;
        -webkit-border-radius: 3px;
        border-radius: 3px;
        margin: 11px 8px 0 0;
    }

    #idm_categories ul.subforums {
        margin: 0px 0 10px 35px;
        font-size: 0.9em;
        line-height: 1.5;
    }

The Javascript associated with this: 与此相关的Javascript:

toggleCategory: function(e, elem)
    {
        Event.stop(e);

        var group = $( elem ).up('li');
        var subgroup = $( group ).down('.subforums');

        if( !$( group ) || !$( subgroup ) )
        {
            Debug.write("Can't find parent or subforums");
            return;
        }

        if( $( group ).hasClassName('closed') )
        {
            new Effect.BlindDown( $( subgroup ), { duration: 0.2 } );
            $( group ).removeClassName('closed').addClassName('open');
        }
        else
        {
            new Effect.BlindUp( $( subgroup ), { duration: 0.2 } );
            $( group ).removeClassName('open').addClassName('closed');
        }

    },

ToggleCategory is registered here: ToggleCategory在这里注册:

ipb.delegate.register('.cat_toggle', ipb.idmportal.toggleCategory);

It is hard to know without seeing the whole javascript library but there are a couple of things you can try. 没有看到整个javascript库很难知道,但是您可以尝试一些方法。 Depending how the onclick event handler is added it might be this will work. 根据onclick事件处理程序的添加方式,可能会起作用。

  echo "<a href='#' class='cat_toggle' id='not sure what would go here'>Scripture</a>";

It is also possible this will work, but I doubt it based on the code you showed above: 这也可能会起作用,但是基于您上面显示的代码,我对此表示怀疑:

  echo "<a href='#' class='closed' id='not sure what would go here'>Scripture</a>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM