我有一个画廊unite gallery。
当窗口小于768像素时,我需要将网格位置从右更改到底部。
$(window).on('resize load', function () {
let w = window.innerWidth;
if(w <= 768){
jQuery("#gallery").unitegallery({
gallery_theme: "grid",
theme_panel_position: "bottom"
});
} else if(w > 768) {
jQuery("#gallery").unitegallery({
gallery_theme: "grid",
theme_panel_position: "right"
});
}但是,只有当窗口onload不在onresize中时,此代码才会更改。
发布于 2018-06-22 09:26:07
我用本地设置检查了您的代码,并且运行良好。现在您需要检查JS插件unitegallery最终是否返回JS对象。如果是这样的话,那么只有我们可以将jquery进一步绑定到元素。
您也可以尝试获取元素对象并将其存储在这样的变量中,
var gallary = $('#gallery');
$(window).on('resize load', function () {
let w = window.innerWidth;
if(w <= 768){
gallery.unitegallery({ // Notice the change here.
gallery_theme: "grid",
theme_panel_position: "bottom"
});
} else if(w > 768) {
gallery.unitegallery({ // Notice the change here.
gallery_theme: "grid",
theme_panel_position: "right"
});
}
});https://stackoverflow.com/questions/50983121
复制相似问题