2025年6月3日更新
修改了函数responsive(o, w) ,参考模板meiyi
function responsive(o, w) {
var breakpoints = [{
name: "cols-xxl",
width: 1400,
cols: 6
},
{
name: "cols-xl",
width: 1200,
cols: 5
},
{
name: "cols-lg",
width: 992,
cols: 4
},
{
name: "cols-md",
width: 768,
cols: 3
},
{
name: "cols-sm",
width: 576,
cols: 2
},
{
name: "cols-xs",
width: 200,
cols: 1
}
];
// 按宽度从大到小排序
breakpoints.sort((a, b) => b.width - a.width);
var cols = 2; // 默认值
for (var i = 0; i < breakpoints.length; i++) {
var breakpoint = breakpoints;
if (w >= breakpoint.width) {
// 优先使用元素上定义的属性值
var attrValue = o.attr(breakpoint.name);
if (attrValue !== undefined && attrValue !== "") {
cols = parseInt(attrValue) || breakpoint.cols;
} else {
cols = breakpoint.cols;
}
// 找到最匹配的断点后立即返回
return cols;
}
}
return cols; // 如果所有断点都不匹配,返回默认值
} |