简体   繁体   English

显示/隐藏离子按钮中的图片

[英]show / hide pictures on pressed button in ionic

I'm writing an App in Ionic 3, where I want to show pictures which are hidden with the 我正在用Ionic 3编写应用程序,我想在其中显示隐藏在

document.getElementById("ImgID").style.display = "none";

Attribute. 属性。 Therefore I took a button which will change the Attribute to 因此,我点击了一个按钮,将Attribute更改为

document.getElementById("ImgID").style.display = "";

My .ts file: 我的.ts文件:

  button_tapped(){
    document.getElementById("ImgID1").style.display = "";
    document.getElementById("ImgID2").style.display = "";
    document.getElementById("ImgID3").style.display = "";
  }

My .html file for the button: 我的按钮的.html文件:

<ion-img    
   class = "button_img_1"   
   (click)="button_tapped()"   
   src="path_to_image"> 
</ion-img>

My .html file for the Image: 我的图片的.html文件:

<ion-img 
  class = "Image_1"
  id = "Image_1"
  src="path_to_image">
</ion-img>

my .css for the image: 我的图像的.css

.Image_1{
        width: 10%;
        height: 0;
        position: absolute;
        padding-bottom: 3%;
        top: 65%;
        left: 20%;
    }

So, if I start the app with not showing the picture, and press the button, the images wont show up, just a grey square at their position. 因此,如果我启动应用程序时未显示图片,然后按按钮,则图像将不会显示,其位置仅显示一个灰色方块。 But if I implement another button for hiding the image, start the app showing the pictures, press the button to hide them, and press the "show"-button, they appear like they should. 但是,如果我实现了另一个用于隐藏图像的按钮,启动了显示图片的应用程序,请按该按钮将其隐藏,然后按“显示”按钮,它们将显示为应有的样子。

Does anyone know where my problem is? 有人知道我的问题在哪里吗?

IONIC uses Angular. IONIC使用Angular。 So you can also use *ngIf to show/hide the image(s) on tap. 因此,您也可以使用* ngIf来显示/隐藏点击的图像。 You put the *ngIf on the image(s). 您将* ngIf放在图像上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM