0

我正在尝试根据其折叠或展开将静态“显示/隐藏公告”标题更改为动态“显示公告”或“隐藏公告”。目前,无论内容是折叠还是展开,它都只显示“显示/隐藏公告”,我想将其更改为动态。

我的代码:

    <div class="collapsibleContainer" title="Show/Hide Announcement">
        <img src="images/announce.jpg" />
    </div>

我的脚本:

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $(".collapsibleContainer").collapsiblePanel();
    });
</script>
<script>
(function($) {
    $.fn.extend({
        collapsiblePanel: function() {
        // Call the ConfigureCollapsiblePanel function for the selected element
        return $(this).each(ConfigureCollapsiblePanel);
    }
  });
})(jQuery);


function ConfigureCollapsiblePanel() {
    $(this).addClass("ui-widget");

    // Check if there are any child elements, if not then wrap the inner text within a new div.
    if ($(this).children().length == 0) {
    $(this).wrapInner("<div></div>");
    }    

    // Wrap the contents of the container within a new div.
    $(this).children().wrapAll("<div class='collapsibleContainerContent ui-widget-content'></div>");

    // Create a new div as the first item within the container.  Put the title of the panel in here.
    $("<div class='collapsibleContainerTitle ui-widget-header'><div>" + $(this).attr("title") + "</div></div>").prependTo($(this));



    // Assign a call to CollapsibleContainerTitleOnClick for the click event of the new title div.
    $(".collapsibleContainerTitle", this).click(CollapsibleContainerTitleOnClick);
}


function CollapsibleContainerTitleOnClick() {
    // The item clicked is the title div... get this parent (the overall container) and toggle the content within it.
    $(".collapsibleContainerContent", $(this).parent()).slideToggle();
}

</script>

我的 CSS:

.collapsibleContainer
{
    margin: 0 auto;
    width: 550px;
    padding-bottom: 10px;

}

.collapsibleContainerTitle
{
    cursor:pointer;
}

.collapsibleContainerTitle div
{
    padding-top:5px;
    padding-left:10px;
    color:#FFFFFF;
    font-family: 'Capriola';
    font-weight: 400;
    background-images: url(images/bg.png);
}

我更新的 CSS 以显示不透明度,但它改变了文本。我只希望背景和边框淡出。悬停为 1.0:

.collapsibleContainerTitle div
{
    padding-top:5px;
    padding-left:10px;
    color:#FFFFFF;
    font-family: 'Capriola';
    font-weight: 400;
    background-images: url(images/bg.png);
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}

.collapsibleContainerTitle div:hover
{
    padding-top:5px;
    padding-left:10px;
    color:#FFFFFF;
    font-family: 'Capriola';
    font-weight: 400;
    background-images: url(images/bg.png);
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}
4

2 回答 2

1

你必须移动这个脚本块

<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $(".collapsibleContainer").collapsiblePanel();
    });
</script>

在第二个脚本块下方。

这是小提琴:

http://jsfiddle.net/EWJby/

于 2012-08-15T17:49:05.680 回答
1

像这样的东西:

function CollapsibleContainerTitleOnClick() {
    $(".collapsibleContainerContent", $(this).parent()).slideToggle(function() {
        $(".collapsibleContainerTitle", $(this).parent()).children(':first')
           .text($(this).is(':visible')?'Hide Announcement':'Show Announcement');
    });
}

小提琴

于 2012-08-15T17:50:22.383 回答