如何设置非像素位置?我试试这个
var stack = { "dir1": "down", "dir2": "right", "firstpos1": 50, "firstpos2": 50 };
但我这很糟糕,因为屏幕分辨率不同。
Necroposting,但可能对其他搜索者有所帮助。我没有js重新计算的解决方案:
js:
new PNotify({
...
addclass: 'pnotify-center'
});
CSS:
.pnotify-center {
right: calc(50% - 150px) !important;
}
这里有一个类似的问题有答案。根据堆栈文档中的第一个示例,您可以通过在 before_open 中设置顶部/左侧 css 属性来居中通知的初始位置。每次调整窗口大小时,您还需要重新定位通知。
function get_center_pos(width, top) {
// top is empty when creating a new notification and is set when recentering
if (!top) {
top = 30;
// this part is needed to avoid notification stacking on top of each other
$('.ui-pnotify').each(function() {
top += $(this).outerHeight() + 20;
});
}
return {
"top": top,
"left": ($(window).width() / 2) - (width / 2)
}
}
$(document).ready(function() {
new PNotify({
title: "this is center",
text: "blablabla",
opacity: 0.90,
type: "info",
width: "390px",
before_open: function(PNotify) {
PNotify.get().css(get_center_pos(PNotify.get().width()));
}
});
$(window).resize(function() {
$(".ui-pnotify").each(function() {
$(this).css(get_center_pos($(this).width(), $(this).position().top))
});
});
});