Change icon image size on SweetAlert

余生长醉 提交于 2019-12-10 18:11:02

问题


I'm trying for change icon image size on SweetAlert. In the .css file I see:

.sweet-alert .sa-icon {
    width: 80px;
    height: 80px;
    border: 4px solid gray;
    -webkit-border-radius: 40px;
    border-radius: 40px;
    border-radius: 50%;
    margin: 20px auto;
    padding: 0;
    position: relative;
    box-sizing: content-box; }

I have changed this values:

 width: 80px;
 height: 80px;

But not change nothing. My .png file is showed in a predefinite size. Suggestions?


回答1:


use the "imageSize" object class in your controller.

  swal({  title: "Oops...",
          text: "Please have a title and body in your post.",
          imageUrl: "../../../img/oopsface.png",
          imageSize: '600x600'
  });

(if you want to modify your sweet alert in this way, you need to use this formatting to call the alert)




回答2:


swal({
  title: "Oops...",
  text: "Please have a title and body in your post.",
  imageUrl: "../../../img/oopsface.png",
  //instead of imageSize use imageWidth and imageHeight
  imageWidth: 600,
  imageHeight: 600,
});



回答3:


It works fine for me. Try removing .sa-icon.

.sweet-alert  {
    width: 80px;
    height: 80px;
    border: 4px solid gray;
    -webkit-border-radius: 40px;
    border-radius: 40px;
    border-radius: 50%;
    margin: 20px auto;
    padding: 0;
    position: relative;
    box-sizing: content-box; }
<img src="http://placehold.it/350x150" class="sweet-alert">



回答4:


In my case, my img class was overwriting imageWidth and imageHeight. For solving this I had to add a custom class on the swal init like this:

swal({
    title: "Title",
    text: "Swal text",
    imageUrl: "/example/image.png",
    imageClass: "contact-form-image",
    confirmButtonText:"Ok",
});

And define a the class on your style.css:

.contact-form-image {
    width: 144px;
    height: 144px;
}



回答5:


'imageHeight' for image height and 'imageWidth' for image width

swal({        
    title: 'Alert!',        
    text: 'Content',        
    imageUrl: 'assets/images/user.png',        
    imageHeight: 80, 
    imageWidth: 80,       
    imageClass:'img-responsive rounded-circle',        
    animation: false        
});
  1. 'title' for alert title
  2. 'text' for alert content
  3. 'imageUrl' for embed image url from website
  4. 'imageHeight' for image size(height)
  5. 'imageWidth' for image size(width)
  6. 'imageClass' for your custom image class/other class added

HTML Output like

<img src="assets/images/user.png" class="img-responsive rounded-circle" height="80" width="80" >




回答6:


for current versions, what is mentioned no longer works, for buttons and image

taste this

swal({
      title: "Search...",
      text: "please, wait",
      icon: "../../images/gif/blue.gif",
      buttons: false,
      closeOnClickOutside: false
    });

and this

.swal-icon img{
  width: 120px;
  height: 120px;
}



回答7:


I FIND THIS TO SOLVE MY PROBLEM

swal({
  title: "Oops...",
  text: "Please have a title and body in your post.",
  imageUrl: "../../../img/oopsface.png",
  //instead of imageSize use imageWidth and imageHeight
  imageWidth: 600,
  imageHeight: 600,
});


来源:https://stackoverflow.com/questions/32238017/change-icon-image-size-on-sweetalert

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