jQuery fullcalendar div 更大的日历不拉伸很好

发布于 2025-01-01 15:58:33 字数 1265 浏览 3 评论 0原文

我有完整的日历工作。但我有一个侧边栏,用户可以折叠它,然后内容框会变大,但是当用户这样做时,日历就不那么好了。

所以我正在考虑窗口调整大小功能,但这仅在浏览器窗口更改时才有效,那么当容器变大或变小时如何使 fullcalendar 做出反应?

显示日历的 JS:

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar').fullCalendar({
    header: {
       left: 'prev,next',
        center: 'title',
        right: 'month,basicWeek,basicDay'
    },
    editable: true
});

侧边栏隐藏和显示按钮的类是 .hide-btn

隐藏和显示侧边栏的 JS:

$(".hide-btn").click(function(){
    if($("#left").css("width") == "0px"){
        $("#left").animate({width:"230px"}, 500 );
        $("#right").animate({marginLeft:"230px"}, 500);
        $("#wrapper, #container").animate({backgroundPosition:"0 0"}, 500);
        $(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left:"223px"}, 500);
    }
    else{
        $("#left").animate({width:"0px"}, 500 );
        $("#right").animate({marginLeft:"0px"}, 500);
        $("#wrapper, #container").animate({backgroundPosition:"-230px 0px"}, 500);
        $(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left:"-7px"}, 500);
    }
});

这是发生的情况的屏幕截图: 在此处输入图像描述

I have the fullcalendar working. But i have a sidebar users can collapse this then the content box gets bigger but when a user do this then the calendar is not so nice as it was.

So i was thinking of the window resize function but this only works when the browser window is changed so how can make it that fullcalendar reacts when the container gets bigger or smaller?

The JS to show the calendar:

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar').fullCalendar({
    header: {
       left: 'prev,next',
        center: 'title',
        right: 'month,basicWeek,basicDay'
    },
    editable: true
});

The class of the sidebar hide and show button is .hide-btn

The JS for hide and show the sidebar:

$(".hide-btn").click(function(){
    if($("#left").css("width") == "0px"){
        $("#left").animate({width:"230px"}, 500 );
        $("#right").animate({marginLeft:"230px"}, 500);
        $("#wrapper, #container").animate({backgroundPosition:"0 0"}, 500);
        $(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left:"223px"}, 500);
    }
    else{
        $("#left").animate({width:"0px"}, 500 );
        $("#right").animate({marginLeft:"0px"}, 500);
        $("#wrapper, #container").animate({backgroundPosition:"-230px 0px"}, 500);
        $(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left:"-7px"}, 500);
    }
});

Here is a screenshot what happend:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那些过往 2025-01-08 15:58:33

就这么简单:

$(window).trigger("resize");

Fullcalendar 的调整大小函数在内部绑定到使用 jQuery 的窗口调整大小事件,因此如果您使用 jQuery 触发该事件,一切都很棒。唯一的小问题是,您还将同时触发与窗口的调整大小事件绑定的任何其他内容。这应该不是问题,因为窗口的大小与原来的大小相同,这应该相当于无操作,但效率有点低。如果您碰巧需要在 fullcalendar 中专门触发调整大小功能,则只能通过破解 fullcalendar 脚本来实现。如果你问的话我可以告诉你怎么做。

因为您正在使用动画,所以您需要在动画完成后调用此函数,因为在此之前位置值不会完全更改。你这样做:

...
  $(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left:"223px"}, 500,
    function() { $(window).trigger("resize"); });
} else {
...
  $(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left:"-7px"}, 500,
    function() { $(window).trigger("resize"); });
}

Its as simple as this:

$(window).trigger("resize");

Fullcalendar's resize function is internally bound to the window resize event using jQuery so if you trigger that event using jQuery everything is great. The only slight problem is that you will also trigger anything else bound to the window's resize event at the same time. That shouldn't be a problem as since the window is the same size as it was this should be equivalent to a no-op, but its a bit inefficient. If you happen to need to specifically fire the resize function inside fullcalendar, that is only possible by hacking the fullcalendar script. I can tell you how to do it if you ask.

Because you are using animations, you will need to call this after the animations complete as the position values will not have fully changed until then. You do this like this:

...
  $(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left:"223px"}, 500,
    function() { $(window).trigger("resize"); });
} else {
...
  $(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left:"-7px"}, 500,
    function() { $(window).trigger("resize"); });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文