How to add fading effect when you toggle css in JavaScript - javascript

I want to add fading effect function when it toggles css stlye attributes and adds classList .
JS:
function darkMode(){
document.body.classList.toggle("dark-theme");
}
function dropDown(){
var options = document.getElementById("options")
options.style.display == "block" ? options.style.display = "none" :
options.style.display = "block";
options.classList.toggle("active")
}
css:
#options{
display: none;
opacity: 0;
position: absolute;
width: 250px;
height: auto;
background: var(--main-bg-color);
border-radius: 5px;
top: 80px;
font-size: 17.5px;
padding: 10px;
box-shadow: 0 4px 9.5px 0 rgba(0, 0, 0, 0.2),0 2px 4px 0 rgba(0, 0, 0, 0.1),inset 0 0 0 1px rgba(255, 255, 255, 0.5);
transition: ease-in-out .125s;
}
#options.active{
top: 65px;
opacity: 1;
transition: ease-in-out .25s;
}
html:
<div class="profile-top" onclick="dropDown()">
<div class="header-nav">
<p class="top-profile-name">
name
</p>
<img class="profile-image" src="..\img\img.png\">
<svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg" class="dropdown-icon" data-v-49c8d0d2="">
<path d="M1 1L5 5L9 1" stroke="white" data-v-49c8d0d2=""></path>
</svg>
</div>
<div class="top-profile-menu" id="options">
<div class="setting-buttons">
<img class="setting-icons" src="..\img\settings.svg\">
<a class="profile-parameters">
settings
</a>
</div>
<div class="setting-buttons" onclick="darkMode()">
<img class="setting-icons" src="..\img\moon.svg\">
<a class="profile-parameters">
dark design
</a>
</div>
<div class="setting-buttons">
<img class="setting-icons" src="..\img\logout.svg\">
<a class="profile-parameters">
logout
</a>
</div>
</div>
</div>
here is full html css and js code at jsfiddle
I have a div element, when you click it, the funcion(darkMode) toggles on, and changes css attribute display: none; to display: block; and addsClassLists, i've added transition attribute in css,but when displays change, transitions doesn't work. I want to make transition work, or somehow add js fade effect, without using jquery.

Add visability: hidden; and visability: visible; in second class

Related

Make image appear when hovering and dissapear when not

I have a div that I want an image to appear when it is hovered on and disappear when moved to another div (which will show another image instead). I tried to set it to display: none from the css file and show it again in jQuery with display: normal, but it feels wrong and apparently is wrong too, any suggestions on how to make it work?
const imgOne = () => {
$("#img1").css('display', 'normal')
}
$(document).ready(function () {
$(".class4").hover(function() {
$('#banner').css('background', '#3a50d9')
$(".hero-name div").css('color', '#ffffff')
$("#banner h2").css("font-family", 'Codystar, cursive')
$('#banner h2').css('font-size', '6vmin')
$("#banner h2").css("font-weight", "700")
$(".hero-name div").css('text-shadow', '-4px 3px 0 #3a50d9, -14px 7px 0 #0a0e27')
})
$(".class5").hover(function() {
$('#banner').css('background', '#005dff')
$(".hero-name div").css('color', '#ffffff')
$("#banner h2").css("font-size", '4vmin')
$("#banner h2").css("font-family", '\"Press Start 2P\", cursive')
$(".hero-name div").css('text-shadow', '-5px 5px 0px #00e6e6, -10px 10px 0px #01cccc, -15px 15px 0px #00bdbd')
// Images
imgOne()
})
}
#img1 {
position: absolute;
left: 41%;
bottom: 60%;
display: none;
}
<!-- Banner Section -->
<section id="banner">
<img id ="img1" src="resources/frozen.svg" alt="pacman" type="png">
<div class="hero-name">
<div class="class1">Y</div>
<div class="class2">O</div>
<div class="class3">U</div>
<div class="class4">R</div>
<div class="class5"></div>
<div class="class6">N</div>
<div class="class7">A</div>
<div class="class8">M</div>
<div class="class9">E</div>
<div class="hero-pro">
<h2>Title Here</h2>
</div>
</div>
An example to clarify: If I hover over the letter "N", an image would appear. When I move to hover to the letter "A", another image would appear and the image that appeared from "N" would disappear.
Im a bit confused at exactly what you want. This may be a case where using :not in CSS will do what you want though. So if I had several images and only wanted the hovered image to be visible I would add
img {
position: absolute;
left: 50%;
top: 20px;
width: 100px;
height: 100px;
opacity: 0;
transition: opacity 0.5s;
}
#backdrop {
position: absolute;
top:0;
width:0;
height: 250px;
z-index:-1;
transition: width .5s;
}
.letters {
width: min-content;
}
h2 {
position: relative;
left: 20px;
}
/*class1 hover effects*/
.class1:hover ~ #img1{
opacity: 1;
}
.class1:hover ~ #backdrop{
width: 100%;
background: #3a50d9;
}
.class1:hover ~ .hero-pro h2, .hero{
font-family: 'Codystar', cursive;
font-size: 30pt;
font-weight: 700;
text-shadow: -4px 3px 0 #3a50d9, -14px 7px 0 #0a0e27;
}
/*class2 hover effects*/
.class2:hover ~ #img2{
opacity: 1;
}
.class2:hover ~ #backdrop{
width: 100%;
background: #005dff;
}
.class2:hover ~ .hero-pro h2, .hero{
font-family: 'Press Start 2P', cursive;
font-size: 30pt;
font-weight: 700;
text-shadow: -5px 5px 0px #00e6e6, -10px 10px 0px #01cccc, -15px 15px 0px #00bdbd;
}
/*class3 hover effects*/
.class3:hover ~ #img3{
opacity: 1;
}
.class3:hover ~ #backdrop{
width: 100%;
background: yellow;
}
.class3:hover ~ .hero-pro h2, .hero{
font-family: 'Press Start 2P', cursive;
font-size: 30pt;
font-weight: 700;
text-shadow: -5px 5px 0px #00e6e6, -10px 10px 0px #01cccc, -15px 15px 0px #00bdbd;
}
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Codystar&display=swap" rel="stylesheet">
<!-- Banner Section -->
<section id="banner">
<div class="hero-name">
<div class="class1 letters">Y</div>
<div class="class2 letters">O</div>
<div class="class3 letters">U</div>
<div class="class4 letters">R</div>
<div class="class5 letters"></div>
<div class="class6 letters">N</div>
<div class="class7 letters">A</div>
<div class="class8 letters">M</div>
<div class="class9 letters">E</div>
<div id="backdrop"></div>
<div class="hero-pro">
<h2>Title Here</h2>
</div>
<img id ="img1" src="https://www.pinclipart.com/picdir/middle/84-849138_gold-chain-gangster-clipart.png" alt="sonic"/>
<img id ="img2" src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Pac_Man.svg/1200px-Pac_Man.svg.png" alt="pacman"/>
<img id ="img3" src="https://www.clipartmax.com/png/middle/27-279319_donkey-kong-png-photo-donkey-kong-king-of-swing.png" alt="dk"/>
<img id ="img4" src="https://www.vhv.rs/dpng/d/574-5744697_tails-sonic-and-all-stars-racing-transformed-tails.png" alt="tails"/>
</div>
Use opacity so your image retains its dimensions.
#img1 {
position: absolute;
left: 41%;
bottom: 60%;
opacity: 0;
}
#img1:hover {
opacity: 1;
}
<!-- Banner Section -->
<section id="banner">
<img id="img1" src="https://placekitten.com/200/300" alt="pacman" type="png">
<div class="hero-name">
<div class="class1">Y</div>
<div class="class2">O</div>
<div class="class3">U</div>
<div class="class4">R</div>
<div class="class5"></div>
<div class="class6">N</div>
<div class="class7">A</div>
<div class="class8">M</div>
<div class="class9">E</div>
<div class="hero-pro">
<h2>Title Here</h2>
</div>
</div>
</section>

How to hide an element by condition in JavaScript?

I'm going to set a parameter for an iframe that sets to 1 or 0. then if the parameter is 1 a div by class="badge" will visible else hide.
How can I define this condition in JavaScript? Thank you for your help :)
This is my HTML and CSS code.
.badge {
font-family: Tahoma;
position: absolute;
left: 0;
bottom: 0;
background: #7bbded;
color: white;
border-radius: 0 0px 0 0;
font-size: 10px;
padding: 1px 6px 0 3px;
}
<iframe scrolling="no" style="" src="" frameborder="0">
<div id="main" style="width: 100%; height: 100%;">
<div class="ad-container" id="container">
<a href="#" target="_blank" onclick="cmp_link_clicked()">
<img class="text-icon" alt="آموزش های فرادرس" title="آموزش های فرادرس" src="https://beta.kaprila.com/a/images/video-icon.gif">
<h3 id="title">فیلم‌ آموزشی <span class="important">تافل <span class="ltr">(TOEFL)</span></span> تشریح آزمون — <strong>کلیک کنید</strong></h3>
<div class="badge" id="badge" style="display: block;">
تبلیغات
</div>
</a>
</div>
</div>
</iframe>
First, get a reference to the div:
var div = document.querySelector('.badge');
Then, add a new class, like show:
if(parameter === 1){
div.classList.add('show');
}
parameter should be the name of your parameter stored in a var.
Besides, you could set display: block in your css file, not as inline style.
Like this:
.badge {
font-family: Tahoma;
position: absolute;
left: 0;
bottom: 0;
background: #7bbded;
color: white;
border-radius: 0 0px 0 0;
font-size: 10px;
padding: 1px 6px 0 3px;
display:none; // ---> Hidden by default
}
.badge.show {
display:block; // --> Visible only when you have .badge and .show classes in the same element
}
To remove the class, you can use classList.remove('show');
if(parameter === 0){
div.classList.remove('show');
}
Check docs here

slidetoggle in pure Javascript

As you might see I have fixed a kind of text box that will pop up when someone is hovering over that image, but honestly I want a slide-up effect that gone up slowly. Must be completely in pure JavaScript (no jQuery please!). Anyone knows how I can do that.
function show(myText) {
var elements = document.getElementsByClassName(myText)
for(var i = 0; i < elements.length; i++){
elements[i].style.visibility = "visible";
}
}
function hide(myText) {
var elements = document.getElementsByClassName(myText)
for(var i = 0; i < elements.length; i++){
elements[i].style.visibility = "hidden";
}
}
.text1 {
position: relative;
bottom: 28px;
text-align: center;
background-color: grey;
width: 100%;
height: 10%;
font-size: 20px;
color: white;
opacity: 0.7;
display: block;
visibility: hidden;
}
.text2 {
position: relative;
bottom: 28px;
text-align: center;
background-color: grey;
width: 100%;
height: 10%;
font-size: 20px;
color: white;
opacity: 0.7;
display: block;
visibility: hidden;
}
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="tumb-wrapper">
<a href="http://www.bbc.com" target="_blank" class="image" onmouseover="show('text1')" onmouseout="hide('text1')">
<img src="https://i.vimeocdn.com/portrait/8070603_300x300" class="project" alt="print-screen"/>
<div class="text1">AAA</div>
</a>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="tumb-wrapper">
<a href="http://www.cnn.com" target="_blank" class="image" onmouseover="show('text2')" onmouseout="hide('text2')">
<img src="https://lh6.ggpht.com/mSKQgjFfPzrjqrG_d33TQZsDecOoVRF-jPKaMDoGIpMLLT1Q09ABicrXdQH6AZpLERY=w300" class="project" alt="print-screen"/>
<div class="text2">BBB</div>
</a>
</div>
</div>
</div>
Here is a version of it that's totally javascript free, just using CSS. I'm going to edit this soon with a slight javascript addition (this current version requires you to have a fixed size).
.caption {
height: 250px;
width: 355px;
overflow: hidden;
}
.caption-image {
height: 100%;
}
.caption-text {
color: white;
padding: 10px;
background: rgba(0, 0, 0, 0.4);
transition: transform 400ms ease;
}
.caption-image:hover + .caption-text,
.caption-text:hover {
transform: translateY(-100%);
}
<div class="caption">
<img class="caption-image" src="http://faron.eu/wp-content/uploads/2013/05/Cheese.jpg" />
<div class="caption-text">Some words about how cheesy it is to use a picture of cheese for this example!</div>
</div>
<div class="caption">
<img class="caption-image" src="https://top5ofanything.com/uploads/2015/05/Tomatoes.jpg" />
<div class="caption-text">There's nothing witty to say about a tomato, maybe some you say I say stuff. But honstly I can't think of anything...</div>
</div>
Version with JS sizing:
Basically the same idea, but when the page is loading it sets certain styles so the images can be what ever size you like.
var captionSel = document.querySelectorAll('.caption');
for (let i = 0; i < captionSel.length; i++) {
let image = captionSel[i].querySelector(":scope > .caption-image");
let text = captionSel[i].querySelector(":scope > .caption-text");
text.style.width = image.clientWidth - 20 + "px";
captionSel[i].style.height = image.clientHeight + "px";
}
.caption {
overflow: hidden;
}
.caption-text {
color: white;
padding: 10px;
background: rgba(0, 0, 0, 0.4);
transition: transform 400ms ease;
}
.caption-image:hover + .caption-text,
.caption-text:hover {
transform: translateY(-100%);
}
<div class="caption">
<img class="caption-image" src="http://faron.eu/wp-content/uploads/2013/05/Cheese.jpg" />
<div class="caption-text">Some words about how cheesy it is to use a picture of cheese for this example!</div>
</div>
<div class="caption">
<img class="caption-image" src="https://top5ofanything.com/uploads/2015/05/Tomatoes.jpg" />
<div class="caption-text">There's nothing witty to say about a tomato, maybe some you say I say stuff. But honstly I can't think of anything...</div>
</div>
I'll give it to you even better: No javascript at all!
This is possible with pure CSS:
.tumb-wrapper {
position: relative;
overflow: hidden;
}
.text {
text-align: center;
background-color: grey;
width: 100%;
height: 10%;
font-size: 20px;
color: white;
opacity: 0.7;
display: block;
position: absolute;
bottom: -30px;
transition: 300ms;
left: 0;
}
.tumb-wrapper:hover .text {
bottom: 28px;
}
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="tumb-wrapper">
<a href="http://www.bbc.com" target="_blank" class="image">
<img src="https://i.vimeocdn.com/portrait/8070603_300x300" class="project" alt="print-screen"/>
<div class="text">AAA</div>
</a>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="tumb-wrapper">
<a href="http://www.cnn.com" target="_blank" class="image">
<img src="https://lh6.ggpht.com/mSKQgjFfPzrjqrG_d33TQZsDecOoVRF-jPKaMDoGIpMLLT1Q09ABicrXdQH6AZpLERY=w300" class="project" alt="print-screen"/>
<div class="text">BBB</div>
</a>
</div>
</div>
</div>
The transition css property animates whatever change you make. This way, when you hover over the .tumb-wrapper div, the .text div will slide up.
You should note however, that ancient IE versions won't be able to use this
I usually do this with only CSS.
Just save the first and second image right next to each other on one file... then you use css to change the position of the background image. To make things nicer i add a css-animation to the movement of the background image.
Example of my code:
<div id="thumb_Wrapper">
<div class="_Thumb">
<img src="images/Thumb.jpg" class="Animate_left">
</div>
</div>
The CSS
#_Container{position:absolute; bottom -60px; right:2px; width:626px; height:100px;}
._Thumb{position:relative; margin-right:4px; width:100px; height:80px; display:block; float:left; background:#EFEFEF; overflow:hidden;}
._Thumb > img{position:absolute; left:0; height:100%; background-size:cover; background-position:center;}
._Thumb > img:hover{left:-18px; cursor:pointer;}
CSS Animation
.Animate_left{transition:left .3s;}
Now all you have to do is swap out the image.
onHover - the image in the thumbnail will smoothly slide to the left; revealing the rest of the image/ showing the other image.
You can set how far to the left(or right) you want the thumb-image to first appear by adjusting the value of 'left' in the ._Thumb class.
You can set how far the image slides on hover by adjusting the img:hover{left:-18px} to what ever you like; instead of 18px.

How to mask two half images and on hover show a full image with an nice animation

I doesn’t know how to do the following with jQuery.
I have created a page hero with two sections (red/black):
What I want is, when hovering over the black one for example, it will expand over the red section, so you get a full black box. The same result I want of course for the red section:
How should I make this work?
var redSection = $('#red');
var blackSection = $('#black');
redSection.on('mouseover', function() {
// Do something - overlay the other section
});
The HTML markup is as follow:
<section id="hero">
<figure id="urbandesign">
<a href=“#" target="_blank">
<img src="images/urbandesign.jpg" alt="Urban Design">
</a>
</figure><!-- End figure -->
<figure id="photography">
<a href=“#" target="_blank">
<img src="images/photography.jpg" alt="Photography">
</a>
</figure><!-- End figure -->
</section><!-- End section#hero -->
And the CSS:
#hero {
height: 480px; /* Default 500px */
padding: 0;
position: relative;
overflow: hidden;
z-index: 1;
background: url(../images/hero.jpg) no-repeat center; /* remove */
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#hero figure {
position: absolute;
top: 0;
background: #FFF;
}
#hero img {
width: 100%;
max-width: none;
position: relative;
opacity: 0.4;
}
The final result I want to replace the red and black section with images.
Look out to your response! Thank you.
A mix of CSS3 and jQuery with Graceful Degradation should sort this.
CSS
.page {
position:fixed;
width:100%;
height:100%;
overflow:hidden;
}
.black {
background:#000;
width:50%;
height:100%;
position:absolute;
width:100%;
left:-50%;
transform:skew(30deg,0);
transition:0.5s ease-in-out;
z-index:1;
}
.red {
background:#ff0000;
width:50%;
height:100%;
position:absolute;
width:100%;
right:-50%;
transform:skew(30deg,0);
transition:0.5s ease-in-out;
}
.red:hover {
transform:skew(0);
transform:translate(-50%,0);
}
.black:hover {
transform:skew(0);
transform:translate(50%,0);
}
.inactive {
z-index:-1
}
HTML
<div class="page">
<div class="black"></div>
<div class="red"></div>
</div>
jQuery
The jQuery is necessary to fix a z-index problem with the last element in the DOM tree that ruins the fluid animation.
$(document).ready(function(){
$('.black').hover(function(){
$('.red').addClass('inactive');
},function(){
$('.red').removeClass('inactive');
});
$('.red').hover(function(){
$('.black').addClass('inactive');
},function(){
$('.black').removeClass('inactive');
});
});
Be aware that adding any content to the two divs you will have to add an inner div and reset the skew with 'transform:skew(-30deg,0);'. The prefixed versions of transition and transform will also need adding.
JSFiddle Reference
You could do this using svg's path for the shape, pattern for the image and a little bit of JavaScript for handling the mouseover and mouseleave events.
var hero = document.getElementById('hero');
var animLeft = document.getElementById('anim-left');
var animRight = document.getElementById('anim-right');
hero.addEventListener('mouseover', function(e) {
(e.target.id == 'left') ? animRight.beginElement() : animLeft.beginElement();
})
hero.addEventListener('mouseleave', function(e) {
(e.target.id == 'left') ? animRight.endElement() : animLeft.endElement();
})
<svg id="hero" width="600" height="200" viewBox="0 0 600 200">
<defs>
<pattern id="image-left" patternUnits="userSpaceOnUse" width="600" height="200" viewBox="0 0 600 200">
<image xlink:href="http://dummyimage.com/600x200/40000c/000" width="600" height="200" />
</pattern>
<pattern id="image-right" patternUnits="userSpaceOnUse" width="600" height="200" viewBox="0 0 600 200">
<image xlink:href="http://dummyimage.com/600x200/002a33/fff" width="600" height="200" />
</pattern>
</defs>
<a xlink:href="#">
<path id="right" d="M0,0 h600 v200 h-600z" fill="url(#image-right)" />
</a>
<a xlink:href="#">
<path id="left" d="M0,0 h350 l-100,200 h-250z" fill="url(#image-left)" />
<animate id="anim-left" xlink:href="#left" attributeType="XML" attributeName="d" from="M0,0 h350 l-100,200 h-250z" to="M0,0 h0 l-100,200 h0z" dur="1" begin="indefinite" repeatCount="1" fill="freeze" />
<animate id="anim-right" xlink:href="#left" attributeType="XML" attributeName="d" from="M0,0 h350 l-100,200 h-250z" to="M0,0 h700 l-100,200 h-600z" dur="1" begin="indefinite" repeatCount="1" fill="freeze" />
</a>
</svg>
A simple CSS only solution with no additional re-paints, etc.:
.parent {
overflow: hidden;
position: absolute;
width: 90%;
height: 90%;
}
.item {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
transition: transform 1s, z-index 1s;
z-index: 1;
overflow: hidden;
}
.item .image {
transition: transform 1s;
}
.item:hover {
transform: translate3d(0px, 0px, 0px);
z-index: 100;
}
.item:hover .image {
transform: skewX(0deg);
}
.red {
background: #f00;
transform: translate3d(-50%, 0px, 0px) skewX(-10deg);
}
.red .image {
transform: skewX(10deg);
}
.black {
background: #000;
transform: translate3d(50%, 0px, 0px) skewX(-10deg);
}
.black img {
transform: skewX(10deg);
}
<section class="parent">
<div class="red item">
<img class="image" src="http://placehold.it/450/ff0000/000000" />
</div>
<div class="black item">
<img class="image" src="http://placehold.it/450/000000/ffffff" />
</div>
</section>

Change of icon using jquery

I am trying to change the list icon. Once the list icon is clicked then a list will open and the icon should change the icon to close icon. again on click on close it should change to list icon.
Here is the code what I have tried:
HTML:
<div id="menuLayout">
<a href="#menuLayout" id="openMenuLayout">
<img src='http://icons.iconarchive.com/icons/visualpharm/icons8-metro-style/32/Timeline-List-Grid-List-icon.png' />
<img src="http://seotobiz.com/images/icon_close.png" style='display:none;'/></a>
<nav id="menuLayoutList">
<ul>
<li>
<form id="search">
<input type="search" placeholder="Search...">
</form>
</li>
<li>Home</li>
<li>About Us</li>
<li>Key Facts</li>
<li>Team</li>
<li>Register</li>
<li>Contact</li>
</ul>
</nav>
</div>
Jquery:
$("#openMenuLayout").click(function(e){
debugger;
if ($('#menuLayout').hasClass('open-menu')){
$('#menuLayout').removeClass('open-menu');
$('#openMenuLayout').find('img').removeClass().addClass('opened_icon');
$(this).css('display','block');
} else {
$('#menuLayout').addClass('open-menu');
$('#openMenuLayout').find('img').removeClass().addClass('open-menu_icon');
$(this).css('display','block');
}
e.preventDefault();
});
Css:
#menuLayout {
display: block;
position: fixed;
width: 280px;
height: 100%;
z-index: 99;
top: 0;
left: -280px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
transition: left 0.2s ease-in-out;
-ms-transition: left 0.2s ease-in-out;
-o-transition: left 0.2s ease-in-out;
-moz-transition: left 0.2s ease-in-out;
-webkit-transition: left 0.2s ease-in-out;
-webkit-perspective: 1000;
-webkit-backface-visibility: hidden;
-webkit-transform: translate(0px, 0px);
background-color: #b11c1c;
background-image: -moz-linear-gradient(center top , #b11c1c, #AD3335);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#b11c1c), to(#AD3335));
background-image: -webkit-linear-gradient(top, #b11c1c, #6A0001);
background-image: -o-linear-gradient(top, #b11c1c, #6A0001);
background-image: linear-gradient(to bottom, #b11c1c, #6A0001);
background-repeat: repeat-x;
filter: progid:dximagetransform.microsoft.gradient(startColorstr='#ffb11c1c', endColorstr='#ffAD3335', GradientType=0);
filter: progid:dximagetransform.microsoft.gradient(enabled=false);
}
#openMenuLayout {
position: absolute;
background-color: rgba(0, 0, 0, 0.3);
width: 32px;
height: 32px;
font-size: 16px;
color: #FFF;
line-height: 32px;
text-align: left;
z-index: 999;
top: 20px;
right: -52px;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
}
img {
max-width: 100%;
}
#menuLayout.open-menu {
left: 0;
}
#menuLayout.open-menu #openMenuLayout {
left: 20px;
right: auto;
}
nav#menuLayoutList {
position: relative;
margin: 70px 0;
}
nav#menuLayoutList ul {
position: relative;
margin: 0;
}
New Link
What you want to achieve is not that hard.
I suggest you to use div elements instead of image elements and, use the css property background-image to define it.
This enables you to use two seperate css classes (with different background images), one for the opened menu and one for the closed one.
Further, it is now possible to use css sprites to avoid image flickering due not loaded resources and to avoid multiple http requests.
Your implementation should look similar to this. Just replace background-color with background-image. If you deploy your application remember that you can avoid image flickering with the sprite technique.
http://jsfiddle.net/V5vg9/
I think you search toggleClass:
$("#openMenuLayout").click(function(e){
$(this).toggleClass('close');
}
then define in CSS a open class and a close class with the open and close background-image.
Why not use hide and show functions? is ver most simple
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<div id="menuLayout">
<a href="#menuLayout" id="openMenuLayout">
<img class="list" src='http://icons.iconarchive.com/icons/visualpharm/icons8-metro-style/32/Timeline-List-Grid-List-icon.png' style='display:none;' />
<img class="close" src="http://seotobiz.com/images/icon_close.png" /></a>
<nav id="menuLayoutList">
<ul>
<li>
<form id="search">
<input type="search" placeholder="Search...">
</form>
</li>
<li><a class="a" href="javascript:;" id="home">Home</a></li>
<li><a class="a" href="javascript:;" id="aboutLayout">About Us</a></li>
<li><a class="a" href="javascript:;" id="KeyLayout">Key Facts</a></li>
<li><a class="a" href="javascript:;" id="teamLayout">Team</a></li>
<li><a class="a" href="javascript:;" id="#">Register</a></li>
<li><a class="a" href="javascript:;" id="contactLayout">Contact</a></li>
</ul>
</nav>
</div>
<script type="text/javascript">
$('.a').click(function(){
if($(this).hasClass("v")){
$('.list').hide();
$('.close').show();
$(this).toggleClass("v");
}else{
$('.list').show();
$('.close').hide();
$(this).toggleClass("v");
}
});
</script>
Now, u need detect with $(this).attr("id"); for anchor

Categories

Resources