1

I am trying to create ON-OFF switch by referring the link

Here i can not use the FontAwesome reference in the index.html file and what i have done is i have copied the font-awesome-css file in my project. But the switch ON-OFF button is not getting displayed.

Here i have deleted the reference from index.html and the content of font-awesome.min.css is copied on my style.css file My requirement is to create ON-OFF switch based on the model value(Boolean).

and it should have edit (ON/OFF) feature in it.

Can anyone suggest why the css file didn't work or is there any other way i can do it .

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
jubi
  • 569
  • 1
  • 10
  • 34

3 Answers3

7

Fontawesome simple switch

<style>
     .active, .inactive {
            font-size: 26px;
            cursor: pointer;
        }

        .active, .inactive {
            font-size: 26px;
            cursor: pointer;
        }

        i.active {
            color: #5cb85c;
        }

        i.inactive {
            color: #d9534f;
        }
    </style> 

<i class="fa fa-toggle-on" ng-class="isActive?'active':'fa-rotate-180 inactive'" ng-click="isActive=!isActive" /> 

"isActive"(bool) is the switch status enter image description here

Rajeev
  • 381
  • 3
  • 9
1

I have copied the code from https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_switch

<!DOCTYPE html>
<html>
<head>
<style>
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {display:none;}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}
</style>
</head>
<body>

<h2>Toggle Switch</h2>

<label class="switch">
  <input type="checkbox">
  <div class="slider"></div>
</label>

<label class="switch">
  <input type="checkbox" checked>
  <div class="slider"></div>
</label><br><br>

<label class="switch">
  <input type="checkbox">
  <div class="slider round"></div>
</label>

<label class="switch">
  <input type="checkbox" checked>
  <div class="slider round"></div>
</label>

</body>
</html> 
Lini Susan V
  • 1,135
  • 1
  • 8
  • 25
1

OUTPUT

<html lang="en">

<head>
  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  <script language="javascript">
    angular
      .module('myApp', ['ngMaterial'])
      .controller('switchController', switchController);

    function switchController($scope) {
      $scope.data = {
        switch1: true
      };
      $scope.message = 'false';
      $scope.onChange = function(state) {
        $scope.message = state;
      };
    }
  </script>
</head>

<body ng-app="myApp">
  <div id="switchContainer" ng-controller="switchController as ctrl" layout="column" ng-cloak>
    <md-switch ng-model="data.switch1" aria-label="Switch 1">
      Switch 1: {{ data.switch1 }}
    </md-switch>

  </div>
</body>

</html>
Biyu
  • 513
  • 1
  • 5
  • 30