【问题标题】:Unable to update jQuery mCustomScrollbar无法更新 jQuery mCustomScrollbar
【发布时间】:2013-07-11 01:42:53
【问题描述】:

我正在使用来自 http://manos.malihu.gr/jquery-custom-content-scroller/ 的自定义滚动条。

我在包含 gridview 的 div 上使用它。当新行添加到 Gridview 时,如果超出大小,则不会显示滚动条。

我还有另一个问题里面有一个 div,我正在使用一个按钮来切换该 div 的显示。

我无法更新滚动条

(function($) {
$(window).load(function() {
 $("#rightFixed").mCustomScrollbar({
scrollInertia: 150,
autoHideScrollbar: true,
updateOnBrowserResize: true,
updateOnContentResize: true,
theme: "dark-2"
 });
});
})(jQuery);

$(function () {
$("#showTax").click(function () {
$("#cartTaxDiv").slideToggle();
$(this).text($(this).text() == 'Show Tax' ? 'Hide Tax' : 'Show Tax');
$('#rightFixed').mCustomScrollbar("update");
});
});

滚动条初始化事件在$(window).load,而按钮点击在$(document).ready

你能帮我吗??

【问题讨论】:

    标签: jquery asp.net jquery-ui gridview scrollbar


    【解决方案1】:

    我已经找到解决办法了。

    对于slideToggle,我们所要做的就是将Update 放在一个函数中并在toggle 中调用它。即切换完成时调用该函数。

    function updateScrollbar() {
        $('#rightFixed').mCustomScrollbar("update");
    }
    
    $("#showTax").click(function () {
        $("#cartTaxDiv").slideToggle(updateScrollbar); // Call the update Scrollbar after the sliding is done.
        $(this).text($(this).text() == 'Show Tax' ? 'Hide Tax' : 'Show Tax');
    })
    

    这样Toggle问题就解决了。

    来到第二个问题 - GridView。当 GrodView 更新时,滚动条也必须更新。为此,我们必须在每次回发时调用此函数。我没有在这里使用更新面板,所以如果在页面加载中回发,我会调用这个函数。

    if (IsPostBack)
    { Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "updateScrollbar();", true); }
    

    因此问题解决了。

    【讨论】:

    • 感谢分享。很多人没有意识到分享自己的解决方案的重要性和有用性。 +1
    • 另外,对我来说,$("#mydiv").slideToggle(500, updateScrollbar); 效果更好
    猜你喜欢
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多