toastr.options: {
"positionClass": "your-newly-created-div-class"
}
.toast-top-center {
top: 12px;
left:50%;
margin:0 0 0 -150px;
}
toastr.options = {
positionClass: 'toast-top-center'
};
margin:0 0 0 (here caculate the -width/2 px for yourself)
.toast-top-center {
top: 12px;
margin: 0 auto;
left: 50%;
margin-left: -150px;
}
toastr.options = {
positionClass: 'toast-top-center'
};
toastr.success("Your Message Header", "Your Message");
var $notifyContainer = $('#toast-container').closest('.toast-top-center');
if ($notifyContainer) {
// align center
var windowHeight = $(window).height() - 90;
$notifyContainer.css("margin-top", windowHeight / 2);
}
在ngx-toastr的最新版本(^14.1.4)中,有一个本地解决方案可解决此问题。如果您查看toast.css文件,您会看到以下内容:
.toast-center-center {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
当您调用toastr通知时,只需在.ts中使用{positionClass: 'toast-center-center' }
即可。
component-name.ts
import { ToastrService } from 'ngx-toastr';
@Component({
selector: 'app-component-name',
templateUrl: './component-name.component.html',
styleUrls: ['./component-name.component.scss']
})
export class ComponentName implements OnInit {
constructor(private readonly toastrService: ToastrService) { }
ngOnInit(): void {
this.toastrService.toastrConfig.positionClass = 'toast-top-center';
}
}
component-name.scss
.toast-top-center {
top: 12px;
margin: 0 auto;
left: 50%;
margin-left: -150px;
}
containerId
选项?在toastr.js中检查它的使用此处。如果您使用containerId
将参考框架设置为表单,然后使用positionClass
将其定位在中间,那么是否有效? - ruffin