更改toastr通知的位置类

swa*_*eel 27 asp.net-mvc jquery toastr

我想在div点击上改变我的吐司的位置类.

positionclass:未更改为Bottom.?我在这里失踪了什么?

以及如何使用

toastr.optionsOverride ='positionclass:toast-bottom-full-width';

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<head>
    <title></title>
    <script type ="text/javascript" src ="@Url.Content("~/Scripts/jquery-1.6.4.js")"></script>
    <script type ="text/javascript" src ="@Url.Content("~/Scripts/toastr.js")"></script>
    <link rel="stylesheet" type="text/css" href="~/content/toastr.css" />
</head>
<script type="text/javascript">
    $(document).ready(function () {

        // show when page load
        toastr.info('Page Loaded!');

        $('#linkButton').click(function () {
            toastr.optionsOverride = 'positionclass:toast-bottom-full-width';
            // show when the button is clicked
            toastr.success('Click Button', 'ButtonClick', 'positionclass:toast-bottom-full-width');
        });

    });

</script>

<body>
    <div id ="linkButton" > click here</div>
</body>
Run Code Online (Sandbox Code Playgroud)

更新1

调试之后我注意到toastr.js下面的getOptions方法覆盖'positionclass:toast-bottom-full-width'到'toast-top-right'

    function getOptions() {
        return $.extend({}, defaults, toastr.options);
    }
Run Code Online (Sandbox Code Playgroud)

更新2 toastr.js中的第140行未成功将m个optionsOverride扩展到选项.

        if (typeof (map.optionsOverride) !== 'undefined') {
            options = $.extend(options, map.optionsOverride);
            iconClass = map.optionsOverride.iconClass || iconClass;
        }
Run Code Online (Sandbox Code Playgroud)

更新3 位置问题已得到修复,但我必须提到位置等级3次,如下所示.我相信实现这一目标的方式不那么嘈杂.

$('#linkButton').click(function () {

    toastr.optionsOverride = 'positionclass = "toast-bottom-full-width"';
    toastr.options.positionClass = 'toast-bottom-full-width';
     //show when the button is clicked
    toastr.success('Click Button', 'ButtonClick', 'positionclass = "toast-bottom-full-width"');
});
Run Code Online (Sandbox Code Playgroud)

Joh*_*apa 35

您可以像这样设置它,如toastr演示中所示:http://codeseven.github.io/toastr/ 或此演示:http://plnkr.co/edit/6W9URNyyp2ItO4aUWzBB

toastr.options = {
  "debug": false,
  "positionClass": "toast-bottom-full-width",
  "onclick": null,
  "fadeIn": 300,
  "fadeOut": 1000,
  "timeOut": 5000,
  "extendedTimeOut": 1000
}
Run Code Online (Sandbox Code Playgroud)


小智 7

这是一个简单的简单步骤来改变位置......见下文......

在显示消息之前首先声明位置类。

前任: toastr.options.positionClass = 'toast-bottom-right';

然后显示您的消息如下:

Command:烤面包机“成功”

希望它工作顺利....谢谢

我刚刚在我的 Laravel 项目中使用了它......如果你理解它,我会把我的代码放在这里......

<script src="{{ asset('js/toastr.min.js') }}" type="text/javascript"></script>
<script type="text/javascript">


    @if (Session::has('success'))

        toastr.options.positionClass = 'toast-bottom-right';
        toastr.success("{{ Session::get('success') }}");

    @endif


</script>
Run Code Online (Sandbox Code Playgroud)

烤面包机通知


Dou*_*ard 6

雅这里肯定有一个错误......

例如.设置选项有点棘手.我在调用我想要的toast类型之前动态设置它们.第一次,选项无关紧要.下一个吐司似乎拿起了选项,然后在那之后的吐司不会改变.

例如

var logger = app.mainModule.factory('logger', ['$log', function ($log) {

var error = function (msg, data, showtoast) {

    if (showtoast) {
        toastr.options = {
            "closeButton": true,
            "debug": false,
            "positionClass": "toast-bottom-full-width",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "300000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
        toastr.error(msg);
    }
    $log.error(msg, data);
};
var info = function (msg, data, showtoast) {

    if (showtoast) {
        toastr.options = {
            "closeButton": true,
            "debug": false,
            "positionClass": "toast-bottom-right",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "300000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
        toastr.info(msg);
    }
    $log.info(msg, data);
};
var warning = function (msg, data, showtoast) {

    if (showtoast) {
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "positionClass": "toast-bottom-right",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
        toastr.warning(msg);
    }
    $log.warning(msg, data);
};

var success = function (msg, data, showtoast) {

    if (showtoast) {
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "positionClass": "toast-bottom-right",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };

        toastr.success(msg);
    }
    $log.info(msg, data);
};


var logger = {
    success: success,
    error: error,
    info: info,
    warning: warning

};
return logger;
}]);
Run Code Online (Sandbox Code Playgroud)