How can i add CSS style file switcher in onepage website? - javascript

I have created a onepage portfolio website. Now its have 2 main stylesheet.One is default(green) and another one is red. Now i want to make two button where people can switch stylesheet each other without page loading.
You can check demo site here. I want same thing in my website.
I have used below code.It design perfectly but when i click on icon its not expand same as demo site.Here is my code:
HTML(markup):
<div class="theme-settings">
<i class="fa fa-cog fa-spin"></i>
<div class="theme-settings-content">
<ul class="theme-list clearfix">
<li class="active"></li>
<li></li>
</ul>
</div>
</div>
CSS(code for button):
.theme-settings .theme-collapse-btn {
position: absolute;
right: -50px;
top: 50%;
margin-top: -25px;
width: 50px;
height: 50px;
line-height: 50px;
font-size: 30px;
color: #000;
background: #fff;
background: rgba(255, 255, 255, .9);
border-radius: 0 4px 4px 0;
text-align: center;
box-shadow: 0 0 2px rgba(0, 0, 0, .4);
-webkit-box-shadow: 0 0 2px rgba(0, 0, 0, .4);
-moz-box-shadow: 0 0 2px rgba(0, 0, 0, .4)
}
.theme-settings {
position: fixed;
left: -180px;
top: 200px;
z-index: 1020;
box-shadow: 0 0 2px rgba(0, 0, 0, .4);
-webkit-box-shadow: 0 0 2px rgba(0, 0, 0, .4);
-moz-box-shadow: 0 0 2px rgba(0, 0, 0, .4);
width: 180px;
-webkit-transition: left .2s linear;
transition: left .2s linear
}
.theme-settings .theme-settings-content {
padding: 10px 5px;
background: #fff;
position: relative;
z-index: 1020
}
.theme-settings .theme-list {
list-style-type: none;
margin: 0;
padding: 0
}
.theme-settings .theme-list > li {
float: left
}
.theme-settings .theme-list > li + li {
margin-left: 5px
}
.theme-settings .theme-list > li > a {
width: 30px;
height: 30px;
border-radius: 3px;
display: block;
-webkit-transition: all .2s linear;
transition: all .2s linear;
position: relative
}
.theme-settings .theme-list > li.active > a:before {
content: '\f00c';
font-family: FontAwesome;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
font-size: 14px;
color: #fff;
opacity: .4;
filter: alpha(opacity=40);
line-height: 30px;
text-align: center
}
.theme-settings.active {
left: 0
}
.bg-red {
background: #d93240!important
}
.bg-green {
background: #5bb12f!important
}
How can i solve this problem? Or can any one tell me any free plugin for this work. Thanks in advance.

You could, for example, use jQuery and switch between the stylesheets on button click.
<link rel="stylesheet" type="text/css" href="default.css" data-theme-switchable>
And in your JavaScript:
$.when($.ready).then(function() {
$('[data-theme]').on('click', function () {
var $stylesheetName = $(this).data('theme');
$('link[data-theme-switchable]').attr('href', $stylesheetName + '.css');
});
});
But it would in fact be the better approach to just switch the class, i. e. of the body and format accordingly.
$.when($.ready).then(function() {
$('[data-theme]').on('click', function () {
$('body').attr('class', $(this).data('theme'));
});
// maybe set the class to the first found theme on load
$('[data-theme]:first').trigger('click');
});
And then…
body.default { ... }
body.red { ... }

Related

css animation does not get triggered a second time

I have a problem, which is for sure simple to solve, except for me. Let me explain, the snippet below shows a dialogue-box. I added an interaction feedback. If the input field is empty and a user tries to access the cross, the field blinks red.
In case the input field is set, the cross can be clicked which displays options. If this are clicked too the input field blinks green. The problem: Unfortunately it works just once, even than I try to remove those CSS classes afterwards. Further if green appeared once and the input field is empty again, I can´t trigger the red blinking again.
My thoughts are, that JavaScript can´t remove and add CSS classes during the same time action. Or the animation will not start over again. I am not sure. I would be glad if somebody can enlighten me.
var dialogSettingToggle = document.getElementById("dialog-setting-toggle")
var dialogSettingInput = document.getElementById("dialog-setting-input")
dialogSettingToggle.addEventListener("click", function() {
if (isEmpty(dialogSettingInput.value)) {
dialogSettingInput.classList.toggle("dialog-input-alert")
} else {
dialogSettingToggle.classList.toggle("open")
var dialogSettingContext = document.getElementById("dialog-setting-button-context")
dialogSettingContext.addEventListener("click", function() {
dialogSettingInput.classList.remove("dialog-input-alert")
dialogSettingInput.classList.add("dialog-input-confirm")
dialogSettingInput.value = ""
dialogSettingToggle.classList.remove("open")
})
var dialogSettingLink = document.getElementById("dialog-setting-button-link")
dialogSettingLink.addEventListener("click", function() {
dialogSettingInput.classList.remove("dialog-input-alert")
dialogSettingInput.classList.add("dialog-input-confirm")
dialogSettingInput.value = ""
dialogSettingToggle.classList.remove("open")
})
var dialogSettingObject = document.getElementById("dialog-setting-button-object")
dialogSettingObject.addEventListener("click", function() {
dialogSettingInput.classList.remove("dialog-input-alert")
dialogSettingInput.classList.add("dialog-input-confirm")
dialogSettingInput.value = ""
dialogSettingToggle.classList.remove("open")
})
}
})
function isEmpty(str) {
return !str.trim().length
}
body {
height: 100%;
background: #e6e7ee;
}
section {
word-wrap: break-word;
word-break: normal;
width: 95%;
max-width: 350px;
margin: 40px auto;
border-radius: 10px;
}
hr {
color: white;
height: 0px;
cursor: default;
}
h5 {
margin: 10px;
font-size: 1.2em;
font-weight: normal;
color: #7b7e8c;
cursor: default;
}
button {
box-shadow: 6px 6px 10px rgba(0, 0, 0, 0.1), -6px -6px 10px white;
background: #f2f3f7;
cursor: pointer;
border: 0;
padding: 10px;
margin: 7px;
margin-top: 10px;
width: 150px;
font-size: 1rem;
transition-property: background-color, box-shadow;
transition-duration: .2s;
color: #7b7e8c;
}
select {
appearance: none;
width: 270px;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAMi0lEQVR4nO3d6Y9laV0H8Fs9M/rSuec5VQUOCMIIiCyBAUKAYNP3PKe6kbCmgiCOXc9zqhwX3A0hLhQJIS4ZISSEkCEIhLAoxPi3KPsmIIvsuzAD4ouepm3s6anl3vu7y+eTnPfnfPtJfb+pW33PaAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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eQjQPkDwFI7/ghQ/gCwEo4+ApQ/AKyU+x8Byh8AVtJ9jwDlDwAr7f+PAOUPAGvhyghQ/gCwVu4dAcofAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhl/wvAMV8MmL0UcAAAAABJRU5ErkJggg==);
background-repeat: no-repeat;
background-position: right;
background-size: 1.8em;
border-radius: 10px;
padding: 10px;
margin: 7px;
font-size: 1rem;
color: #7b7e8c;
border: 0;
cursor: pointer;
box-shadow: 0 0 transparent, 0 0 transparent, inset 3px 3px 5px rgba(0, 0, 0, 0.1), inset -3px -3px 5px white;
}
input {
width: 270px;
background: #f8f9fb;
border-radius: 10px;
padding: 10px;
margin: 7px;
font-size: 1rem;
color: #7b7e8c;
border: 0;
cursor: text;
box-shadow: 0 0 transparent, 0 0 transparent, inset 3px 3px 5px rgba(0, 0, 0, 0.1), inset -3px -3px 5px white;
}
button:hover,
select:hover,
input:hover {
color: #3498db;
}
button:active {
box-shadow: 0 0 transparent, 0 0 transparent, inset 3px 3px 5px rgba(0, 0, 0, 0.1), inset -3px -3px 5px white;
}
.border-round {
border-radius: 10px;
}
.dialog {
position: absolute;
left: 0;
right: 0;
padding: 10px 20px 20px;
margin-top: 20px;
width: 340px;
min-height: 100px;
font-size: 1.2em;
background: #f2f3f7;
}
.box-shadow {
box-shadow: 6px 6px 10px rgba(0, 0, 0, 0.1), -6px -6px 10px white;
}
.dialog-setting-button-delete {
position: relative;
margin-top: 7px;
width: 40px;
height: 40px;
border-radius: 10px;
background: #ecf0f3;
cursor: pointer;
box-shadow: 6px 6px 10px rgba(0, 0, 0, 0.1), -6px -6px 10px white;
}
.dialog-setting-close {
position: absolute;
width: 25px;
height: 25px;
padding: 0px;
margin: 0px;
left: 350px;
top: 5px;
border-radius: 10px;
background: #ecf0f3;
cursor: pointer;
box-shadow: none;
}
.dialog-input-alert {
animation: input-alert 1.5s;
}
#keyframes input-alert {
from {
background: red;
color: white
}
to {
background: #f8f9fb;
color: #7b7e8c;
}
}
.dialog-input-confirm {
animation: input-confirm 1.5s;
}
#keyframes input-confirm {
from {
background: greenyellow;
color: white
}
to {
background: #f8f9fb;
color: #7b7e8c;
}
}
/****************************************
******** dialog-setting-toggle ***********
****************************************/
.dialog-setting-toggle {
position: relative;
margin-top: 7px;
margin-right: 7px;
width: 40px;
height: 40px;
border-radius: 10px;
background: #ecf0f3;
cursor: pointer;
box-shadow: 6px 6px 10px rgba(0, 0, 0, 0.1), -6px -6px 10px white;
}
.dialog-setting-toggle::before,
.dialog-setting-toggle::after {
content: "";
background: #7b7e8c;
border-radius: 5px;
width: 20px;
height: 5px;
position: absolute;
left: 10px;
top: 18px;
transition: 0.2s ease;
z-index: 1;
}
.dialog-setting-toggle::before {
transform: rotate(0deg);
}
.dialog-setting-toggle::after {
transform: rotate(-90deg);
}
.dialog-setting-toggle:hover::before {
transform: rotate(0deg);
background-color: #3498db;
}
.dialog-setting-toggle:hover::after {
transform: rotate(-90deg);
background-color: #3498db;
}
.dialog-setting-toggle.open::before {
transform: rotate(45deg);
background-color: #3498db;
}
.dialog-setting-toggle.open::after {
transform: rotate(-45deg);
background-color: #3498db;
}
.dialog-setting-toggle.open .dialog-setting-button {
opacity: 1;
pointer-events: auto;
}
.dialog-setting-toggle.open .dialog-setting-button:first-of-type {
right: -50px;
justify-content: center;
align-items: center;
}
.dialog-setting-toggle.open .dialog-setting-button:nth-of-type(2) {
right: -100px;
justify-content: center;
align-items: center;
transition-delay: 0.05s;
}
.dialog-setting-toggle.open .dialog-setting-button:last-of-type {
right: -150px;
justify-content: center;
align-items: center;
transition-delay: 0.1s;
}
.dialog-setting-button {
width: 40px;
height: 40px;
border-radius: 10px;
cursor: pointer;
background: #ecf0f3;
position: absolute;
color: #7b7e8c;
display: flex;
opacity: 0;
pointer-events: none;
box-shadow: inherit;
}
.dialog-setting-button:hover {
transform: scale(1.2);
color: #3498db;
}
<script src="https://kit.fontawesome.com/39094309d6.js" crossorigin="anonymous"></script>
<section id="dialog-setting" class="dialog box-shadow">
<div>
<h5 style="text-align:center">Options</h5>
<button style="float: right" id="dialog-setting-close" class="dialog-setting-close border-round"><i class="fas fa-times"></i></button>
</div>
<hr class="border-round">
<input style="float: left" id="dialog-setting-input" type="search" placeholder="context / link / object" class="item dialog-setting-input"></input>
<div style="float: right" id="dialog-setting-toggle" class="dialog-setting-toggle">
<div title="Kontext" id="dialog-setting-button-context" class="dialog-setting-button"><i class="fab fa-uncharted"></i></div>
<div title="Link" id="dialog-setting-button-link" class="dialog-setting-button"><i class="fas fa-link"></i></div>
<div title="Objekt" id="dialog-setting-button-object" class="dialog-setting-button"><i class="fas fa-server"></i></div>
</div>
</section>
It isn´t the best solution but it is one solution. I added a timeout with the same duration as the animation goes. Works fine for my needs.
dialogSettingToggle.addEventListener("click", function () {
if (isEmpty(dialogSettingInput.value)) {
dialogSettingInput.classList.add("dialog-input-alert")
setTimeout(function() {
dialogSettingInput.classList.remove("dialog-input-alert")
}, 1000)
} else {
dialogSettingToggle.classList.toggle("open")
var dialogSettingContext = document.getElementById("dialog-setting-button-context")
dialogSettingContext.addEventListener("click", function() {
resetInput()
})
var dialogSettingLink = document.getElementById("dialog-setting-button-link")
dialogSettingLink.addEventListener("click", function() {
resetInput()
})
var dialogSettingObject = document.getElementById("dialog-setting-button-object")
dialogSettingObject.addEventListener("click", function() {
resetInput()
})
}
})
function resetInput() {
dialogSettingInput.classList.add("dialog-input-confirm")
setTimeout(function() {
dialogSettingInput.classList.remove("dialog-input-confirm")
}, 1000)
dialogSettingInput.value=""
dialogSettingToggle.classList.remove("open")
}

Window resize function not working for header navigation

I am working on a header navigation which has logo on the left and profile icon on the right in the middle there are some navigation links.
There is a left slide menu made which triggers in when window width is less than 700px. I have triggered slide left menu on window resize event as well. The main navigation has to shift to the responsive menu container on resizing the window width. However it is not working on window resize function.
Here is the codepen link i tried
$("#sidebarCollapse").on('click', function () {
$('#sidebar').toggleClass('active');
});
$(".main-nav li a").on('click', function(){
$(".main-nav li a").removeClass('active');
$(this).addClass('active');
});
// Menu Add Class Left
$(".hamburger-menu").click(function(){
$(".mob-menu").toggleClass("slide-left");
});
// Menu Add Class Close
$('.mdl-layout__obfuscator').click(function(){
$(".mob-menu").removeClass("slide-left");
});
var domWidth = $(window).width();
function moveElements() {
var mobMenu = $('.mob-menu'),
$mainNav = $('.main-nav'),
respNav = $('.resp-nav'),
mainHdr = $(".global-header");
if( domWidth < 700) {
//alert(domWidth);
$('.main-nav').appendTo('.resp-nav');
}
} .
$(window).on('load resize',function() {
// alert('hi');
moveElements();
$(window).resize(function() {
moveElements();
});
});
/* ---------------------------------------------------
GLOBAL HEADER PAGE
----------------------------------------------------- */
textarea,
input,
button {
outline: none;
}
.txtlabel {
font-size: 12px;
text-align: left;
color: #706e6b;
padding-bottom: 11px;
display: block;
}
.global-header {
width: 100%;
display: block;
height: 50px;
box-shadow: 0 2px 4px 0 #e8ebf3;
-moz-box-shadow: 0 2px 4px 0 #e8ebf3;
-webkit-box-shadow: 0 2px 4px 0 #e8ebf3;
position: relative;
background-color: #f1f1f1;
}
.g-logo {
padding: 7px 24px;
float: left;
}
.m-g-logo {
display: none;
padding: 7px 20px;
float: left;
}
.hamburger-menu {
display: none;
}
.resp-nav {
margin-top: 20px;
float: left;
}
.mob-menu {
display: none;
padding: 10px;
box-shadow: 2px 0 3px 0 #b5b7bd;
-moz-box-shadow: 2px 0 3px 0 #b5b7bd;
-webkit-box-shadow: 2px 0 3px 0 #b5b7bd;
/*position: fixed;*/
position: absolute;
-webkit-transform: translateX(-285px);
-ms-transform: translateX(-285px);
transform: translateX(-285px);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
will-change: transform;
-webkit-transition-duration: .2s;
transition-duration: .2s;
-webkit-transition-timing-function: cubic-bezier(.4, 0, .2, 1);
transition-timing-function: cubic-bezier(.4, 0, .2, 1);
-webkit-transition-property: -webkit-transform;
transition-property: transform;
background: #fff;
top: 0;
bottom: 0;
color: #333;
z-index: 9999;
width: 240px;
-webkit-box-shadow: 3px 0px 7px 0px rgba(0, 0, 0, 0.25);
-moz-box-shadow: 3px 0px 7px 0px rgba(0, 0, 0, 0.25);
box-shadow: 3px 0px 7px 0px rgba(0, 0, 0, 0.25);
}
.profile-info {
float: left;
width: 100%;
}
.profile-icon {
width: 23px;
height: 23px;
margin: 8px;
display: block;
}
.profpic {
width: 32px;
height: 32px;
border-radius: 50%;
color: #fff;
background-color: #394961;
float: left;
margin: 5px 0px 5px 5px;
}
.profile-info span {
color: #626579;
font-size: 16px;
margin: 3px 0 0 3px;
}
.prof-name {
float: left;
width: 68%;
margin: 0 0 0 20px;
}
.prof-name a.link {
float: left;
margin: 0 10px 0 3px;
}
.prof-name a.link:first-child {
position: relative;
}
.prof-name a.link:first-child:after {
content: "|";
position: absolute;
right: -10px;
color: #9ea6a9;
}
.icon-hamburger {
height: 5px;
background-color: black;
margin: 6px 0;
width: 20px;
float: left;
border: none;
cursor: pointer;
}
.main-nav {
list-style: none;
float: left;
margin-left: 30px;
}
.main-nav li {
list-style: none;
float: left;
}
.main-nav li a {
color: #626579;
padding: 14px 30px;
display: block;
}
.main-nav li a:hover {
color: #00a0e7;
}
.main-nav li a.active {
color: #00a0e7;
border-bottom: 3px solid #00a0e7;
background-color: #eef0f6;
}
.nav-icon {
float: left;
padding: 10px;
}
.pull-right i[class^='icon-'] {
width: 32px;
height: 32px;
display: block;
}
.icon-search {
background: url("../../imgs/global-header/icn-search.svg") no-repeat 4px 5px;
}
.icon-notification {
background: url("../../imgs/global-header/icn-notification.svg") no-repeat 8px 8px;
}
.icon-profile {
background: #394961 url("../../imgs/global-header/avatar.svg") no-repeat;
position: relative;
margin-right: 30px;
border-radius: 50%;
}
.icon-profile:after {
background: url("../../imgs/global-header/page-1.svg") no-repeat;
display: block;
width: 9px;
height: 6px;
position: absolute;
content: "";
top: 14px;
right: -20px;
}
.icon-profile:before {
background: url("../../imgs/global-header/avatar-icon.svg") no-repeat;
display: block;
width: 16px;
height: 16px;
position: absolute;
content: "";
top: 7px;
right: 8px;
}
.nav-icon:hover {
background-color: transparent;
}
.nav-icon:not(.active):hover {
background-color: #eef0f6;
cursor: pointer;
}
.usage {
list-style: none;
}
.usage ul {
list-style: disc;
list-style-position: outside;
}
/* search */
.srch {
position: relative;
display: inline-block;
margin-right: 30px;
}
.pull-left {
float: left;
}
.pull-right {
float: right;
}
ul,
ol {
margin-top: 0;
margin-bottom: 10px;
}
.ui-front {
list-style: none!important;
background-color: #fff;
color: #626579;
font-size: 12px;
font-weight: 500;
width: 240px!important;
min-width: 110px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
border: 1px solid #F1F5F6;
border-radius: 4px;
padding: 10px 8px!important;
}
.ui-front li {
padding: 8px 8px!important;
cursor: pointer;
}
.slide-left {
-webkit-transform: translateX(0);
-ms-transform: translateX(0);
transform: translateX(0);
z-index: 99999;
}
.mdl-layout__obfuscator {
background-color: transparent;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
visibility: hidden;
-webkit-transition-property: background-color;
transition-property: background-color;
-webkit-transition-duration: .2s;
transition-duration: .2s;
-webkit-transition-timing-function: cubic-bezier(.4, 0, .2, 1);
transition-timing-function: cubic-bezier(.4, 0, .2, 1);
}
.slide-left~.mdl-layout__obfuscator {
background-color: rgba(0, 0, 0, .5);
visibility: visible;
}
.slide-menu {
position: fixed;
-webkit-transform: translateX(-285px);
-ms-transform: translateX(-285px);
transform: translateX(-285px);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
will-change: transform;
-webkit-transition-duration: .2s;
transition-duration: .2s;
-webkit-transition-timing-function: cubic-bezier(.4, 0, .2, 1);
transition-timing-function: cubic-bezier(.4, 0, .2, 1);
-webkit-transition-property: -webkit-transform;
transition-property: transform;
background: #fff;
top: 0;
bottom: 0;
color: #333;
z-index: 9999;
width: 250px;
-webkit-box-shadow: 3px 0px 7px 0px rgba(0, 0, 0, 0.25);
-moz-box-shadow: 3px 0px 7px 0px rgba(0, 0, 0, 0.25);
box-shadow: 3px 0px 7px 0px rgba(0, 0, 0, 0.25);
}
#media only screen and (max-width: 768px) {
.main-nav {
display: block;
width: 100%;
margin: 0;
}
.main-nav ul {
padding: 0;
}
.main-nav ul li {
width: 100%;
margin: 0;
}
.nav-icon:nth-child(3) {
display: none;
}
.g-logo {
display: none;
}
.m-g-logo {
display: block;
padding: 7px 24px;
float: left;
}
.hamburger-menu {
display: block;
}
.global-header .rightmenu {
position: absolute;
right: 12px;
}
.mob-menu {
display: block;
}
.global-header {
width: 100%;
display: block;
height: 500px;
}
}
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<div class="global-header">
<div class="mob-menu">
<div class="profile-info">
<div class="profpic"><i class="profile-icon"></i></div>
<div class="prof-name">
<span>Marvin Duncan</span>
Profile
Logout
</div>
</div>
<div class="resp-nav"></div>
</div>
<div class="pull-left">
Logo
</div>
<nav class="main-nav">
<ul>
<li>Label 1</li>
<li>Label 2</li>
</ul>
</nav>
<div class="pull-right rightmenu">
<div class="nav-icon" title="Profile"><i class="icon-profile">☺</i></div>
</div>
<div class="mob-view">
<span class="hamburger-menu">
<button class="icon-hamburger"></button>
Logo
</span>
</div>
<div class="mdl-layout__obfuscator"></div>
</div>
The problem is probably because this line only happens once:
var domWidth = $(window).width();
You need to place that line of code within your moveElements function, so that it continually checks the width of the window.
Additionally, I'd suggest not using 'appendTo' to move something. It is tricky to move pieces of the DOM around like this and you can get in a mess easily. Better to use CSS to move the display of something. Or, if you can't achieve it with CSS alone - maybe have two instances, and show/hide them as needed.
change $(window).width(); to $(document).width();
i tried and it worked

Make href go to div instead of a page

Basically a href is going to the #popups div and generating a popup on codepen.
However, when I paste that code into a page. It goes to a link. Is there anyway to just trigger that popup event when A href is clicked? I have tried this
Edit: I just want the div popup triggered. I do not want the href to go to a new page.
Test
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
transition: opacity 200ms;
visibility: hidden;
opacity: 0;
}
.overlay.light {
background: rgba(255, 255, 255, 0.5);
}
.overlay .cancel {
position: absolute;
width: 100%;
height: 100%;
cursor: default;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 75px auto;
padding: 20px;
background: #fff;
border: 1px solid #666;
width: 300px;
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
position: relative;
}
.light .popup {
border-color: #aaa;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.popup h2 {
margin-top: 0;
color: #666;
font-family: "Trebuchet MS", Tahoma, Arial, sans-serif;
}
.popup .close {
position: absolute;
width: 20px;
height: 20px;
top: 20px;
right: 20px;
opacity: 0.8;
transition: all 200ms;
font-size: 24px;
font-weight: bold;
text-decoration: none;
color: #666;
}
.popup .close:hover {
opacity: 1;
}
.popup #content {
max-height: 400px;
overflow: auto;
}
.popup p {
margin: 0 0 1em;
}
.popup p:last-child {
margin: 0;
}
Test
<div id="popups" class="overlay">
<div class="popup">
<h2>Info box</h2>
<a class="close" href="#">×</a>
<div id="content">
Old Content
</div>
</div>
</div>
try this:
$('a').on('click',function(e){
e.preventDefault();
});

How to get value from toggle-button yes/No And show retrieve data in button active

Hiii Everyone,
Below is my code to display toggle button yes/no.What i want to do is based on user selection i want to retrieve data.If they choose Yes toggle button javascript variable should have yes string or else no string.
HTML Code
<label class="switch">
<input class="switch-input" type="checkbox" />
<span class="switch-label" data-on="Yes" data-off="No"></span>
<span class="switch-handle"></span>
</label>
CSS
.switch {
position: relative;
display: block;
vertical-align: top;
width: 100px;
height: 30px;
padding: 3px;
margin: 0 10px 10px 0;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF 25px);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF 25px);
border-radius: 18px;
box-shadow: inset 0 -1px white, inset 0 1px 1px rgba(0, 0, 0, 0.05);
cursor: pointer;
}
.switch-input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
}
.switch-label {
position: relative;
display: block;
height: inherit;
font-size: 10px;
text-transform: uppercase;
background: #eceeef;
border-radius: inherit;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
}
.switch-label:before, .switch-label:after {
position: absolute;
top: 50%;
margin-top: -.5em;
line-height: 1;
-webkit-transition: inherit;
-moz-transition: inherit;
-o-transition: inherit;
transition: inherit;
}
.switch-label:before {
content: attr(data-off);
right: 11px;
color: #aaaaaa;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.switch-label:after {
content: attr(data-on);
left: 11px;
color: #FFFFFF;
text-shadow: 0 1px rgba(0, 0, 0, 0.2);
opacity: 0;
}
.switch-input:checked ~ .switch-label {
background: #0088cc;
border-color: #0088cc;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
}
.switch-input:checked ~ .switch-label:before {
opacity: 0;
}
.switch-input:checked ~ .switch-label:after {
opacity: 1;
}
.switch-handle {
position: absolute;
top: 4px;
left: 4px;
width: 28px;
height: 28px;
background: linear-gradient(to bottom, #FFFFFF 40%, #f0f0f0);
background-image: -webkit-linear-gradient(top, #FFFFFF 40%, #f0f0f0);
border-radius: 100%;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.switch-handle:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
margin: -6px 0 0 -6px;
width: 12px;
height: 12px;
background: linear-gradient(to bottom, #eeeeee, #FFFFFF);
background-image: -webkit-linear-gradient(top, #eeeeee, #FFFFFF);
border-radius: 6px;
box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
}
.switch-input:checked ~ .switch-handle {
left: 74px;
box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
}
/* Transition
========================== */
.switch-label, .switch-handle {
transition: All 0.3s ease;
-webkit-transition: All 0.3s ease;
-moz-transition: All 0.3s ease;
-o-transition: All 0.3s ease;
}
I refreed this code from http://www.htmllion.com/css3-toggle-switch-button.html
Below is the output
I tried this jquery to get get:
alert($(this).attr("data-on"));
I dont know how to get selected button data and similarly after get data it will store in database and i want to retrieve from database either yes or no it should be selected as default which will retrieve from database.How can i do with this.Result which i tried in jquery is returning undefined values.Please anyone help me to get out of this problem.Thanks in advance.
Try this:
(function() {
$(document).ready(function() {
$('.switch-input').on('change', function() {
var isChecked = $(this).is(':checked');
var selectedData;
var $switchLabel = $('.switch-label');
console.log('isChecked: ' + isChecked);
if(isChecked) {
selectedData = $switchLabel.attr('data-on');
} else {
selectedData = $switchLabel.attr('data-off');
}
console.log('Selected data: ' + selectedData);
});
});
})();
For Ref: http://jsbin.com/zizuxo/edit?js,console,output
in pure JS :
var result = document.getElementsByClassName("switch-input")[0].checked ? 'yes' : 'no'
jQuery in compatibility mode :
var result = jQuery('.switch-input').is(':checked')?'yes':'no';
I combined the above
$('.switch-input').on('change', function() {
result = document.getElementsByClassName("switch-input")[0].checked ? 'yes' : 'no';
alert(result);
});

Container is getting unnecessary margin

My html is:-
<!DOCTYPE html>
<html>
<head>
<meta charset="US-ASCII">
<link
rel="stylesheet"
type="text/css"
href="css/index.css"
>
<title>Best company in the USA</title>
</head>
<body>
<div class="menu">
<h2>MENU</h2>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<nav role="navigation">
<div class="navWrap">
<h2 class="navClose"></h2>
<ul>
<li>Home</li>
<li></li>
<li>About us</li>
<li></li>
<li><a href="somelink.com">
Services</a></li>
<li></li>
<li>Locations</li>
<li></li>
<li>Contact Us</li>
<li></li>
</ul>
</div>
</nav>
<div class="content">
<section class="first"></section>
</div>
</body>
</html>
My css is:-
#CHARSET "US-ASCII";
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
::-moz-selection {
background: none repeat scroll 0% 0% #D8262E;
}
::selection {
background: none repeat scroll 0% 0% #D8262E;
}
ul {
list-style: none outside;
clear: both;
}
.menu {
position: absolute;
float: right;
cursor: pointer;
float: right;
z-index: 1000;
top: 25px;
right: 20px;
}
.menu h2 {
display: none;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2)
}
#media only screen and (min-width:768px) {
.menu {
top: 32px;
right: 40px;
}
.menu h2 {
display: inline-block;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
font-family: "Karla", Arial, sans-serif;
font-size: 20px;
margin: 0px 5px 0px 0px;
text-transform: uppercase;
vertical-align: top;
}
}
.menu ul {
display: inline-block;
height: 30px;
margin: 0;
padding: 0;
vertical-align: top;
width: 25px;
margin: 0;
}
.menu ul li {
background: white;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
-ms-border-radius: 2px;
-o-border-radius: 2px;
border-radius: 2px;
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 1px 1px 1px;
-moz-box-shadow: rgba(0, 0, 0, 0.2) 1px 1px 1px;
box-shadow: rgba(0, 0, 0, 0.2) 1px 1px 1px;
height: 3px;
margin: 3px 0;
width: 100%;
}
html,nav,section,div {
display: block;
vertical-align: baseline;
margin: 0px;
padding: 0px;
border: 0px none;
}
nav[role="navigation"] {
background: #00e000;
overflow: hidden;
padding: 0 40px;
position: absolute;
top: 0;
right: 0;
text-align: left;
width: 13em;
z-index: 10;
}
.menu,.content,.first {
-webkit-transition: all 340ms cubic-bezier(0.905, 0.015, 0.65, 0.97);
-webkit-transition-delay: 0s;
-moz-transition: all 340ms cubic-bezier(0.905, 0.015, 0.65, 0.97) 0s;
-o-transition: all 340ms cubic-bezier(0.905, 0.015, 0.65, 0.97) 0s;
transition: all 340ms cubic-bezier(0.905, 0.015, 0.65, 0.97) 0s
}
.first {
background-color: #d8262e;
/* background: no-repeat scroll center transparent; */
width: 100%;
/* height: 600px; */
top: 0;
z-index: 30;
}
.first:before {
height: 100%;
content: "";
display: inline-block;
vertical-align: middle;
background-color: #38262e;
}
.first:after {
background-color: #38262e;
}
.content {
/* margin-top: -8px;
margin-left: -7px;
margin-right:-7px; */
/* padding-top:-10px; */
}
content:before,content:after {
content: "";
display: table;
line-height: 0;
}
content:after {
clear: both;
}
Jquery is:-
$(document) .ready(function () {
windowHeight = 0.9 * $(window) .innerHeight();
$('.first').height(windowHeight);
$(window) .resize(function () {
windowHeight = 0.9 * $(window) .innerHeight();
console.log("height: " + windowHeight);
});
});
So, there is a peculiar problem I'm facing now. Somehow, I'm getting 8-10px or margin from each side in the content class. I have a solution for this. If I comment out the css in .content, it works for me.
But, it would be great to know if my naive solution can get better. Or if somebody would help me point out the root cause for the extra margin, it would be great.
Here is a jsfiddle for this: http://jsfiddle.net/kSdHU/
Thanks.
You should reset your elements.
Just add:
* { margin: 0; padding: 0; }
Demo
To make sure you never run into weird styling issues like this I suggest using a css reset. It will basically reset your browsers default styles so you aren't getting unwanted styling of elements. I normally use Eric Meyers Reset but there are many out there.

Categories

Resources