user11204114
user11204114

Reputation:

Install Hamburger CSS on Angular

My intention is to install the Hamburger CSS from Jonathan Suh on my Angular Project.

I used npm i --s hamburgers which successfully added the package. I also added its CSS file to my angular.json file.

When I try to add a hamburger using the code below, the hamburger is being displayed, but it's not clickable. Why is that?

<button class="hamburger hamburger--collapse" type="button">
    <span class="hamburger-box">
      <span class="hamburger-inner"></span>
    </span>
  </button>

Upvotes: 2

Views: 1390

Answers (2)

לבני מלכה
לבני מלכה

Reputation: 16251

As you comment that you use CSS and in doc write:

.scss source files are available if you use Sass as your CSS precompiler. It’s customizable and modular

Here is alternative with angular and css

Html

<div class="collapse" (click)="ifShow=!ifShow" [ngClass]="{'hide':!ifShow}">
  <span></span>
  <span></span>
  <span></span>
</div>

CSS:

.collapse{
  position: relative;
  cursor: pointer;
}
.collapse span{
    position: absolute;
    width: 40px;
    height: 4px;
    border-radius: 4px;
    background-color: black;
}

.collapse span:nth-child(2) {
    top: 10px;
}
.collapse span:nth-child(3){
    top: -10px;
}

.hide span:nth-child(2) {
   transform:rotate(45deg);
   top:0;
}

.hide span:nth-child(3){
   transform:rotate(-45deg);
   top: 0;
}

.hide span:nth-child(1){
  animation:hideMain 1.5s;
  opacity: 0;
}
.hide span:nth-child(2),.hide span:nth-child(3) {
  animation:hide 1.5s;
}

@keyframes hide{
  0%{
    transform:rotate(0);
  }
  50%{
    top:0;
    transform:rotate(0);
  }
}
@keyframes hideMain{
  49%{
   opacity: 1;
  }
  50%{
  opacity: 0;
  }
}

TS:

 ifShow : boolean = true;

Upvotes: 2

Charitha Goonewardena
Charitha Goonewardena

Reputation: 4724

Steps to follow,

  1. install hamburger package. npm install hamburgers --save
  2. import in styles.scss @import '~hamburgers/_sass/hamburgers/hamburgers.scss';
  3. use hamburger divs in html and toggle the class. (click)="active=!active" [ngClass]="active ? 'is-active' : ''"

Upvotes: 7

Related Questions