javascript - 我如何使用/附加 pnotify 到一个 div

标签 javascript jquery html pnotify

我正在使用 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/

相关文章:

javascript - Kendo 下拉菜单和网格外过滤器

javascript - 将脚本作为字符串添加到文本区域值中

javascript - 需要使用 JavaScript 修改文件名和位置

JavaScript 检查数组对象是否存在或未定义

javascript - 防止用户使用 jquery 或 javascript 重新加载页面

javascript - 选定节点与其导入节点之间的差异

javascript - 是否可以使用 CSS HTML 和 JavaScript 在 B 上执行 A,在 C 上执行 B,在 A 上执行 C?

javascript - window.customElements 在 Chrome 中未定义

javascript - 如何在 React Native 上将 StackNavigator 与 DrawerNavigator 和 SwitchNavigator 一起使用?

JavaScript 变量提升