我正在使用 Pnotify 发送通知,但通知只显示在非常特定的地方。我想将它们附加到我页面的 header 类中,但我不确定该怎么做。
JS:
function showNotify(data){
var notice = $.pnotify({
type: 'success',
delay: 300000,
addclass: (isDevice)? 'body-device stack-topleft':'stack-topleft',
mouse_reset: false
}).click(function(e){
notice.pnotify_remove();
});
}
我想将我的 pnotify 附加到的 HTML 是:
<div class="header">
<div class="col-md-12" data-bind="with: activeRoute"></div>
</div>
最佳答案
来自 http://sciactive.com/pnotify/#demos-simple
function show_stack_context(type) {
if (typeof stack_context === "undefined") stack_context = {
"dir1": "down",
"dir2": "left",
"context": $("#stack-context")
};
var opts = {
title: "Over Here",
text: "Check me out. I'm in a different stack.",
stack: stack_context
};
switch (type) {
case 'error':
opts.title = "Oh No";
opts.text = "Watch out for that water tower!";
opts.type = "error";
break;
case 'info':
opts.title = "Breaking News";
opts.text = "Have you met Ted?";
opts.type = "info";
break;
case 'success':
opts.title = "Good News Everyone";
opts.text = "I've invented a device that bites shiny metal asses.";
opts.type = "success";
break;
}
$.pnotify(opts);
}
所以你会
function showNotify(data){
if (typeof stack_context === "undefined") stack_context = {
"dir1": "down",
"dir2": "left",
"context": $(".header")
};
var opts = {
title: "Over Here",
text: "Notification",
type: 'success',
delay: 300000,
addclass: (isDevice)? 'body-device stack-topleft':'stack-topleft',
mouse_reset: false
stack: stack_context
};
var notice = $.pnotify(opts).click(function(e){
notice.pnotify_remove();
});
}
关于javascript - 我如何使用/附加 pnotify 到一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22821146/