jQuery toggles active state - css

I'm implementing this toggles on my page http://www.creativusmouse.com/Hyperion/html/toggles.html and wanted to have the toggle button to remain orange when it's active. Please find bellow the CSS and jQuery code used.
I believe this is something easy to achieve. Hope someone could help me.
Thank you ;)
jQuery(window).load(function(){
$('.toggle-view li').click(function () {
var text = $(this).children('div.toggle-content');
if (text.is(':hidden')) {
text.slideDown('200');
$(this).children('span').html('<i class="icon-minus"></i>');
} else {
text.slideUp('200');
$(this).children('span').html('<i class="icon-plus"></i>');
}
});
});
/* ======================== CSS ======================== */
.toggle-view {
margin:0;
padding: 0;
list-style-type:none;
}
.toggle-view li {
margin:0px 0px 25px;
position:relative;
cursor:pointer;
display: block;
font-weight: bold;
text-decoration: none;
}
.toggle-view h2 {
font-size:12px;
text-transform:uppercase;
margin:0;
padding:4px 0 4px 40px;
}
.toggle-view span {
background: none repeat scroll 0 0 #80acb9;
color: #fff;
font-size: 12px;
padding: 2px 4px 2px 2px;
position: absolute;
left: 0px;
top: 0;
-webkit-transition: all 0.4s ease;
-moz-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
.toggle-view li:hover h2 {
}
.toggle-view li:hover span {
background: none repeat scroll 0 0;
background:#F63;
color:#fff;
}
.toggle-view .toggle-content {
box-sizing: content-box;
display:none;
padding:10px 35px;
}
.toggle-view ul.square, .toggle-view ul.circle, .toggle-view ul.disc {
margin-left:20px;
}

add another class to the span element.
in CSS add the class selector to the for the span, that is the same as the hover one:
.activetoggle, .toggle-view li:hover span {
background: none repeat scroll 0 0;
background:#F63;
color:#fff;
}
and in javascript add:
$(this).children('span').toggleClass('activetoggle');
I think this might work.
here is a little simplified illustration on jsfiddle
Update: I updated the jsfiddle with your markup and code, and I toggle the class now on the li element
$('.toggle-view li').click(function () {
var text = $(this).children('div.toggle-content');
if (text.is(':hidden')) {
text.slideDown('200');
$(this).children('span').html('<i class="icon-minus"></i>');
} else {
text.slideUp('200');
$(this).children('span').html('<i class="icon-plus"></i>');
}
$(this).toggleClass('activetoggle');
});
to simplify everything a little =) The CSS selector is now .activetoggle span.
jsfiddle

Related

Why is there a delay for the transition of my pseudo elements?

I need to animate both of the element and its pseudo element.
Then I noticed, when I hover, everything is fine. But then I stop hovering, the Home animates first and after that, the pseudo element Link starts animating.
Why it behaves like this? Is there a way to make them animate simultaneously?
Here's a simplified recreation of my problem:
a {
color: blue;
transition: all 1s;
text-decoration: none;
}
a:hover {
color: red;
font-size: 48px;
}
a:hover::before {
color: green;
font-size: 32px;
}
a::before {
content: 'Link:';
transition: all 1s;
}
Home
I'm using MacOS with Chrome Version 83.0.4103.97 (Official Build) (64-bit)
If you can't reproduce the problem, here's a screengrab of it:
I also assigned the default values ​​to ::before and works fine. I think it trying to inherit the default values and it's confusing.
a {
color: blue;
transition: all 1s;
text-decoration: none;
}
a:hover {
color: red;
font-size: 48px;
}
a::before {
content: 'Link:';
transition: all 1s;
font-size: 1rem;
color: blue;
}
a:hover::before {
color: green;
font-size: 32px;
}
Home
Because there is no default font-size for the pseudo element so the pseudo element will inherit the font-size of the a. Here is what is happening:
we initially have both element at font-size X (X is based on your other properties, 16px here)
On hover the pseudo element will have 32px and a will have 48px
when you unhover (and here is the trick) the pseudo element will inherit for a moment the font-size of the a (48px) so your transition will be from 32px to 48px - y where y is changing du to the transition applied to a until the 48px - y is back to X
Same logic apply with coloration because it's also inherited. Simply set a default font-size and color
a {
color: blue;
transition: all 1s;
text-decoration: none;
}
a:hover {
color: red;
font-size: 48px;
}
a:hover::before {
color: green;
font-size: 32px;
}
a::before {
content: 'Link:';
transition: all 1s;
font-size:16px;
color:blue;
}
Home
I found a solution on mouseover it's a bit ugly but at least it's working smoothly
a {
color: blue;
transition: all 1s;
text-decoration: none;
}
a::before {
content: 'Link:';
/* transition: all 1s; */
}
a:hover {
color: red;
font-size: 48px;
}
a:hover::before {
transition: all 1s;
color: green;
font-size: 32px;
}
Home

how to gradually turn the background opacity of a bootstrap navbar into a solid color

The effect that I'm trying to comprehend is used in the Start Bootstrap Grayscale Template.
This is a bootstrap 3.0 implementation.
As you scroll down, the nav area quickly but smoothly changes its color.
I'd like to bring this awesome feature into yamm's mega menu.
http://geedmo.github.io/yamm/
But before I can do that, I must comprehend the overall idea.
Could someone shed some light on this?
The styles that deal with the nav area is as follows;
.navbar {
margin-bottom: 0;
border-bottom: 1px solid rgba(255,255,255,.3);
text-transform: uppercase;
font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif;
background-color: #000;
}
.navbar-brand {
font-weight: 700;
}
.navbar-brand:focus {
outline: 0;
}
.navbar-custom a {
color: #fff;
}
.navbar-custom .nav li a {
-webkit-transition: background .3s ease-in-out;
-moz-transition: background .3s ease-in-out;
transition: background .3s ease-in-out;
}
.navbar-custom .nav li a:hover,
.navbar-custom .nav li a:focus,
.navbar-custom .nav li.active {
outline: 0;
background-color: rgba(255,255,255,.2);
}
.navbar-toggle {
padding: 4px 6px;
font-size: 16px;
color: #fff;
}
.navbar-toggle:focus,
.navbar-toggle:active {
outline: 0;
}
#media(min-width:767px) {
.navbar {
padding: 20px 0;
border-bottom: 0;
letter-spacing: 1px;
background: 0 0;
-webkit-transition: background .5s ease-in-out,padding .5s ease-in-out;
-moz-transition: background .5s ease-in-out,padding .5s ease-in-out;
transition: background .5s ease-in-out,padding .5s ease-in-out;
}
.top-nav-collapse {
padding: 0;
background-color: #000;
}
.navbar-custom.top-nav-collapse {
border-bottom: 1px solid rgba(255,255,255,.3);
}
}
I'm curious to know which sections are responsible for this effect.
Not necessarily what you are looking for, but you could try something like in this fiddle. If you look in the console while scrolling down, you will see the distance from the top as it changes. You can just check the distance and then simply change the class of the menu.
The JS would be something like:
$(window).scroll(function(){
var posTop = $(window).scrollTop() - $('.container').offset().top
console.log('from .container: '+posTop+' | from top of page: '+$(window).scrollTop());
}).trigger('scroll');
Edit: you edited the question and made it more specific, my answer doesn't really apply for what you're asking now.
Later edit: the effect seems to be done from JavaScript, as I suggested. If you look in greyscale.js you can find:
//jQuery to collapse the navbar on scroll
$(window).scroll(function() {
if ($(".navbar").offset().top > 50) {
$(".navbar-fixed-top").addClass("top-nav-collapse");
} else {
$(".navbar-fixed-top").removeClass("top-nav-collapse");
}
});
at the very top of the file. Basically it says that whenever a user scrolls, it checks whether it got 50px lower than the top. If it has, it changes the class of the nav to top-nav-collapse. The smoothing effect comes from CSS, however.

Changing style on bootstrap tabs active

Ok so I'm having some issues changing the active state on my bootstrap tabs. I managed to get the hover to work but there is still some issues I am running into.
This is what I am currently using for the hover, I need the active state to be the same but I'm not sure how to do that.
.services-icon-holder {
border: 2px solid #272727;
border-radius: 50%;
width: 65px;
height: 65px;
margin-bottom: 40px;
}
.services-icon-holder:hover {
background-color: #272727;
cursor: pointer;
}
.services-icon {
font-size: 28px;
color: #272727;
line-height: 2.2 !important;
padding-bottom: 15px;
}
.services-icon-holder:hover .services-icon {
color: #f1f1f1;
cursor: pointer;
-webkit-transition: color 0.5s ease;
}
I also have an issue with the active tab being 1 or so pixels above the rest of the tabs, I used inspect element to try and find where this is coming from but to no success.
You can check out the live site here (just go to services section to see the tabs)
Please manage this code , this is the css structure
.services .nav > li > a {
outline:none ! important;
border: none;
}
.services .nav > li.active > a .services-icon-holder {
background-color: #272727;
cursor: pointer;
}
In /css/style.css:517
.services .nav > li > a {
/* Add below */
border: none;
}
And for active state color, you can add this code to your style
.nav-tabs > li.active .services-icon-holder {
background-color: #000;
}
.nav-tabs > li.active .services-icon-holder > .services-icon {
color: #fff;
}

CSS active menu item

Hi I'm trying to modify a web template which doesn't have different colors for active menu items. I've tried various changes to be able to adjust this. Any ideas? Here is the css:
/** TOP MENU **/
.top_menu .moduletable {
margin:0;
}
.top_menu li {
margin:0px 0 0 5px ;
padding:0;
float:left;
height:100px;
list-style : none;
background : transparent url(../images/top_menu_left.png) 0 0 no-repeat;
opacity:0.6;
-ms-filter: "prodig:DXImageTransform.Microsoft.Alpha(Opacity=60)"; /* fix IE8 */
filter: apha(opacity = 60); /* fix IE7 */
-webkit-transition : all 0.4s ease-in-out;
-moz-transition : all 0.4s ease-in-out;
-ms-transition : all 0.4s ease-in-out;
-o-transition : all 0.4s ease-in-out;
transition : all 0.4s ease-in-out;
}
.top_menu li:hover {
opacity:1;
-ms-filter: "prodig:DXImageTransform.Microsoft.Alpha(Opacity=100)"; /* fix IE8 */
filter: apha(opacity = 100); /* fix IE7 */
}
.top_menu li a {
display:block;
color: #24221E/*8c8c8c*/;
text-shadow:0 0 3px #fff;
background : transparent url(../images/top_menu_right.png) 100% 0 no-repeat;
text-decoration:none;
text-transform: none;
font-weight:bold;
font-size:90%;
margin-right:-13px;
padding: 60px 22px 4px 20px;
height:40px;
}
Any help would be greatly appreciated
I see that you are using Joomla as a Content Management System and you have to use a class to style an item, for example active, and then you can use CSS to assign a different styling for this item.
.active {
text-decoration: underline;
font-weight: bold;
}
If you want to change the color of the link you need to adress the a tag directly using the following code.
.active a {
color: red;
}
You might find this answer also useful: Joomla - how to hightlight the menu item for active page

CSS Horizontal sub menu - IE 6,7 both dont working, tried with whatever hover

I'm not expert about css menus. But I know basic system to make css menu.
I used this system before and works, but this time it is not working.
The site is http://www.uniethos.com. Please check this site
This menu works with all other latest Browsers. But not with IE 6 & 7. I know IE6 don't support hover except anchor. So before I was using Whatever Hover. But this time it is not working and even with IE7. I don't know why its happening. May be there could be some problem with my css. Please check the css.
If you don't have IE 6 or 7 installed you can run one from http://spoon.net/browsers/. Require to install one plugin.
The CSS I'm using for the menu is
.glossymenu{
background: #B4B3B3;
height: 30px;
width: 100%;
padding: 0;
margin: 0;
display:inline-block;
position:relative;
}
.glossymenu ul
{
list-style: none;
padding: 0px;
margin: 0;
padding-left: 0px;
}
.glossymenu li ul
{
display:none;
position:absolute;
width: 80%;
top:30px;
left:0px;
background-color:#5B0C10;
border:0px;
z-index: 99;
}
.glossymenu li li a
{
padding: 0px 10px 0px 10px;
}
.glossymenu li li a:hover
{
background : #871016;
}
.glossymenu li{
float:left;
padding: 0;
}
.glossymenu li a{
float: left;
display:block;
position:relative;
color:#FFF;
text-decoration: none;
font-family: sans-serif;
font-size: 13px;
font-weight: bold;
padding:0 0 0 16px; /*Padding to accomodate left tab image. Do not change*/
height: 30px;
line-height: 30px;
text-align: center;
cursor: pointer;
}
.glossymenu li a b{
float: left;
display: block;
padding: 0 24px 0 8px; /*Padding of menu items*/
}
.glossymenu li.current a, .glossymenu li a:hover{
color: #FFF;
background: #5B0C10;
background-position: left;
text-decoration: none;
}
.glossymenu li a:visited{
text-decoration: none;
}
.glossymenu ul li:hover ul
{
display: block;
}
Well I didn't found the problem. But I fixed the menu with custom Javascript code.
sfHover = function() {
var sfEls = document.getElementById("glossymenu").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" over";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" over\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
People those are also facing the same problem may find this helpfull.
Thanks.
Ofcourse whatever:hover is best. But I don't know why that was not working.
If you face the same problem, you can use this javascript. But you have to understand the code.
sfHover = function() {
// You may have to change the "glossymenu" id with your one
var sfEls = document.getElementById("glossymenu").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" over";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" over\\b"), "");
}
} } if (window.attachEvent) window.attachEvent("onload", sfHover);
In my case, I have a div id named "glossymenu". You have to change this with your id.
And also have to declare another CSS class named "over".
In my case -
.glossymenu li:hover ul, .glossymenu li.over ul
{
display: block;
}
This is enough for one level dropdown menu. You don't need whatever:hover if its ok with you.

Resources