How to insert an image into an alertify.js alert with JavaScript?

末鹿安然 提交于 2019-12-08 07:00:30

问题


I want to create a pop-up dialog with a large image and an OK button and for this I'am trying to customize the alerts of alertify.js .

My idea was to create a custom css class for all these "popup-alerts" with an default image url, and then change the url background-image: url(images/level_10.jpg); when I create the pop-up to the right image with JavasScript (because you can pass in a custom cssClass when you call the function);

I'm not sure whether this is possible at all.

Or is there maybe better way to customize alertify.js to achieve this?


回答1:


You can override the CSS class of alertify.

Just look the example below: http://www.fabien-d.github.io/alertify.js/assets/js/lib/alertify/alertify.bootstrap.css

In your case, you just want to override .alertify CSS class like this :

.alertify.popup1 {
    background: url(path/file1.png);
}
.alertify.popup2 {
    background: url(path/file2.png);
}
/* etc */

And use the Javascript like this:

$("alert1").onclick = function () {
 alertify.alert("This is an alert dialog", function() {}, 'popup1');
};
$("alert2").onclick = function () {
 alertify.alert("This is an other alert dialog", function() {}, 'popup2');
};

Check this fiddle for a workin example ;)



来源:https://stackoverflow.com/questions/19104517/how-to-insert-an-image-into-an-alertify-js-alert-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!