列表视图内部可折叠面板的平滑动画

Smoothing Animation of Collapsible Panels Inside Listviews

本文关键字:平滑 动画 视图 内部 可折叠 列表      更新时间:2023-09-26

我有以下代码来平滑可折叠面板上的动画,它工作得很好:

<script type="text/javascript">
    function pageLoad(sender, args) {
        smoothAnimation();
    }

    function smoothAnimation() {
        var collPanel = $find(("<%= CollapsiblePanelExtender.ClientID %>"));
        collPanel._animation._fps = 30;
        collPanel._animation._duration = 0.5;
    }
</script>  

现在,我还有一个列表视图,与上面的面板分离,在每个项目中都有一个可折叠的面板扩展程序。我想将"smoothAnimation()"函数应用于它们中的每一个,但我不知道如何做到这一点,因为数据绑定为每个项目提供了唯一的ID。

有人知道如何在javascript中处理这个问题吗?非常感谢您的帮助。

使用OnItemCreated事件,并使用以下内容:

protected void ListItems_Created(object sender, ListViewItemEventArgs e)
{
    CollapsiblePanelExtender cpe = (CollapsiblePanelExtender)e.Item.FindControl("collapsePanelID");
    cpe.Attributes.Add("onload", cpe.ClientID + "._animation._fps = 30;");
    cpe.Attributes.Add("onload", cpe.ClientID + "._animation._duration = 0.5;");
}

此代码未经测试,但它是使此代码正常工作所需的全部内容。