我正在使用http://microsoft.com/webservices/在我的网站上显示通知。 我遇到了一个问题,我在其中添加通知显示它们然后,如果我想显示不同的通知并添加它,我也会看到旧的通知。 工作流程是:
为了添加通知,我使用以下内容:
var noteOption = {
// whether to hide the notification on click
clickToHide : true,
// whether to auto-hide the notification
autoHide : false,
globalPosition : 'bottom right',
// default style
style : 'bootstrap',
// default class (string or [string])
className : 'error',
// show animation
showAnimation : 'slideDown',
// show animation duration
showDuration : 400,
// hide animation
hideAnimation : 'slideUp',
// hide animation duration
hideDuration : 200,
// padding between element and notification
gap : 10
}
var note = "My Error Message"
$.notify.defaults(noteOption);
$.notify(note, "error");
现在问题是,在添加新通知之前如何清除通知?
谢谢,
Liron
答案 0 :(得分:4)
这是因为您调用的函数始终返回Notification的新实例 最好的方法是清除旧的通知容器:
$('.notifyjs-corner').empty();
遗憾的是,他们没有像$.singletonNotify()
答案 1 :(得分:0)
这对我有用:
var image: UIImage? {
didSet {
photoView.image = nil
layout()
photoView.image = image
}
}
override func draw(_ rect: CGRect) {
if photoView.image != nil {
setPictureFrame()
layout()
}
}
private func setPictureFrame() {
let photoRect = photoView.contentClippingRect
photoView.clearConstraints()
photoView.heightAnchor.constraint(equalToConstant: photoRect.height).isActive = true
photoView.widthAnchor.constraint(equalToConstant: photoRect.width).isActive = true
}
private func layout() {
var layoutConstraints: [NSLayoutConstraint] = []
if photoView.image == nil {
photoView.clearConstraints()
photoView.constraintsFillWhole(view: photoViewContainer)
}
layoutConstraints += [
photoView.centerXAnchor.constraint(equalTo: self.centerXAnchor),
photoView.centerYAnchor.constraint(equalTo: photoViewContainer.centerYAnchor),
]
NSLayoutConstraint.activate(layoutConstraints)
}
https://github.com/mouse0270/bootstrap-notify/issues/136#issuecomment-204051563