- 11,968
- Australia
- I_Grayson_Fox_I
I am making a webpage and am having trouble getting the code for the switch I want to work, I assume it is an issue with the jQuery but on the demo site the code works fine.
I have used code examples from this site as well as others that require jQuery and they've worked fine.
While I am a nub at web design, I understand the basics of it
This is the code used in the script tags
This is the code used in the style tags
This is the code used in the body tags
Code example from this site
https://codepen.io/XDBoy018/pen/PwNrYr
I have used code examples from this site as well as others that require jQuery and they've worked fine.
While I am a nub at web design, I understand the basics of it
This is the code used in the script tags
Code:
$(".switch").on('click', function(){
$(this).toggleClass("active");
if ($('.span').text() == "ON")
$('.span').text("OFF");
else
$('.span').text("ON");
});
This is the code used in the style tags
Code:
@import url(https://fonts.googleapis.com/css?family=Montserrat:700);
.switch {
position: absolute;
height: 60px;
width: 170px;
background: #8b8b8b;
cursor: pointer;
-moz-transform: skew(-30deg);
-ms-transform: skew(-30deg);
-webkit-transform: skew(-30deg);
transform: skew(-30deg);
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
-moz-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
-webkit-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
text-indent: 45%;
line-height: 60px;
-moz-box-shadow: 0px 0.5px 2.5px #6f6f6f;
-webkit-box-shadow: 0px 0.5px 2.5px #6f6f6f;
box-shadow: 0px 0.5px 2.5px #6f6f6f;
}
.switch .span {
font-family: 'Montserrat', sans-serif;
-moz-transform: skew(30deg);
-ms-transform: skew(30deg);
-webkit-transform: skew(30deg);
transform: skew(30deg);
-moz-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
-webkit-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
font-size: 30px;
z-index: -1;
color: #666;
}
.switch:before {
-moz-transition: all 0.2s ease-out;
-o-transition: all 0.2s ease-out;
-webkit-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
position: absolute;
content: "";
height: 55px;
width: 40px;
top: 2.5px;
left: 2.5px;
cursor: pointer;
background: #eee;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
-moz-box-shadow: 2.5px 0 5px #6f6f6f;
-webkit-box-shadow: 2.5px 0 5px #6f6f6f;
box-shadow: 2.5px 0 5px #6f6f6f;
}
.switch.active {
-moz-transform: skew(30deg);
-ms-transform: skew(30deg);
-webkit-transform: skew(30deg);
transform: skew(30deg);
background: #9bc148;
}
.switch.active .span {
-moz-transform: skew(-30deg);
-ms-transform: skew(-30deg);
-webkit-transform: skew(-30deg);
transform: skew(-30deg);
text-indent: 20%;
color: #eee;
}
.switch.active:before {
left: 127.5px;
-moz-box-shadow: -2.5px 0px 5px #6f6f6f;
-webkit-box-shadow: -2.5px 0px 5px #6f6f6f;
box-shadow: -2.5px 0px 5px #6f6f6f;
}
This is the code used in the body tags
Code:
<div class='switch'>
<div class='span'>OFF</div>
</div>
Code example from this site
https://codepen.io/XDBoy018/pen/PwNrYr