我一直在寻找使Telerik RadWindow响应式工作的解决方案。有两件事需要响应,即RadWindow中的内容和RadWindow本身。
问题:
根据Telerik:“ RadWindow不支持响应大小更改,并且它不能根据视口自动更改大小,因为无法严格定义这种情况下的行为”
最佳答案
解决方案:(RadWindow内部的内容需要响应,RadWindow本身也需要响应)
RadWindow内容:
在此示例中,我使用CSS Grid使RadWindow的内容具有响应性。
.sectionSearch {
display: grid;
grid-gap: 3px;
grid-template-columns: repeat(auto-fit, 200px);
align-items: end;
max-width: 809px;
}
RadWindow的响应度:
每个this文章都可以将视口设置为屏幕的百分比。然后,您可以使用JavaScript媒体查询来调整视口的高度和宽度的百分比,具体取决于屏幕的大小。
通过结合并修改包括this在内的一些帖子,以下示例解决方案可以满足我对RadWindow作出响应的需求。
var $ = $telerik.$;
var radwindow;
function pageLoad() {
radwindow = $find("<%= radwindow.ClientID%>");
}
$(window).resize(function () {
if (radwindow.isVisible()) {
setWindowsize();
}
});
function setWindowsize() {
//var viewportWidth = $(window).width();
//var viewportHeight = $(window).height();
/* ==================================================== */
// media query event handler
if (matchMedia) {
var mqls = [ // array of media queries
window.matchMedia("(min-width: 0px) and (max-width: 399px)"),
window.matchMedia("(min-width: 400px) and (max-width: 600px)"),
window.matchMedia("(min-width: 600px) and (max-width: 800px)"),
window.matchMedia("(min-width: 800px) and (max-width: 1000px)"),
window.matchMedia("(min-width: 1000px) and (max-width: 4000px)")
]
for (i = 0; i < mqls.length; i++) { // loop though media queries
mqls[i].addListener(WidthChange); // listen for queries
WidthChange(mqls[i]); // call handler func at runtime
}
}
// media query change
function WidthChange(mql) {
if (mqls[0].matches) {
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
radwindow.setSize(Math.ceil(viewportWidth * 90 / 100), Math.ceil(viewportHeight * 90 / 100));
} else if (mqls[1].matches) {
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
radwindow.setSize(Math.ceil(viewportWidth * 90 / 100), Math.ceil(viewportHeight * 60 / 100));
} else if (mqls[2].matches) {
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
radwindow.setSize(Math.ceil(viewportWidth * 90 / 100), Math.ceil(viewportHeight * 40 / 100));
} else if (mqls[3].matches) {
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
radwindow.setSize(Math.ceil(viewportWidth * 90 / 100), Math.ceil(viewportHeight * 40 / 100));
} else if (mqls[4].matches) {
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
radwindow.setSize(Math.ceil(viewportWidth * 70 / 100), Math.ceil(viewportHeight * 45 / 100));
}
}
radwindow.center();
}