在屏幕调整大小时自动移动剑道通知

Sli*_*ain 3 c# kendo-ui asp.net-mvc-5

有谁知道如何在调整窗口大小时移动剑道通知?即当窗口全屏显示时。

我有一个问题,当有人将我的应用程序更改为全屏时,通知会覆盖一些链接,我想避免这种情况。

任何帮助和建议将不胜感激。

Jar*_*zak 5

您可以使用 jQuery 移动它。例如,要使其距右下角保持 10 个像素,您可以使用以下代码:

$(window).on('resize', function(e){
    var notificationContainer = $(".k-notification").parent();
    notificationContainer.css('top', $(window).height() - notificationContainer.outerHeight() - 10);
    notificationContainer.css('left', $(window).width() - notificationContainer.outerWidth() - 10);
});
Run Code Online (Sandbox Code Playgroud)

请注意,如果您计划在同一时间有多个通知,您将需要更复杂的代码,否则它们会相互重叠:

//move all notfication starting 10px from bottom right corner
$(window).on('resize', function(e){
    var notifications = $(".k-notification");

    var maxTop = 0, lastElement;
    notifications.each(function(index, value){
        var thisPosition = $(value).parent().position();
        if(thisPosition.top > maxTop){
            maxTop = thisPosition.top;
            lastElement = $(value).parent();
        }
    });

    var newTop = $(window).height() - lastElement.outerHeight() - 10;
    var topChange = maxTop - newTop;

    notifications.each(function(index, value){
        var notificationContainer = $(value).parent();
        notificationContainer.css('top', notificationContainer.position().top - topChange);
        notificationContainer.css('left', $(window).width() - notificationContainer.outerWidth() - 10);
    });
});
Run Code Online (Sandbox Code Playgroud)