jquery - Triggering an animation on a div by clicking a button using addClass/removeClass with Javascript -


so i'm trying trigger animation clicking on button using addclass , removeclass javascript.

i'm not bad @ html/css strating learn javascript editing snipets.

so here's mine can tell me why div won't rotate when click black button ?

thanks in advance !

<button class="menu-circle"></button>  <img class='imgblock' src="http://lorempixel.com/400/200/" alt="" />  .menu-circle { height: 100px; width: 100px; background-color: #000000; border-radius: 50%; position: absolute; top: 50%; left: 50%; transform: translatex(-50%) translatey(-50%); transition: .1s; z-index: 100; border: none; }  .menu-circle:hover { height: 115px; width: 115px; }  .menu-circle:active { height: 100px; width: 100px; }  .imgblock { display: block; margin: 20px; -webkit-transition-duration: 1s; -moz-transition-duration: 1s; -o-transition-duration: 1s; transition-duration: 1s; }  .rotate { -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); }  $('.menu-circle').on('click', function(){ $('img .imgblock').addclass('rotate'); $('img .imgblock .rotate').removeclass('rotate'); }); 

working fiddle :

http://jsfiddle.net/leokaj/rv5pr/366/

you have several problems fiddle:

  1. wrong class names: in js $('.menucircle') , in html - class="menu-circle"
  2. you don't need space between img , class in jquery selector $('img .imgblock') - space means you're looking .imgblock class inside img tag (which impossible).
  3. .current class not defined nor in html, nor in css, appear in js

here's fiddle fixed problems , works: demo

js:

$('.menu-circle').on('click', function(){     var $img = $('.crossrotate');     if (!$img.hasclass('rotate')) {         $img.addclass('rotate');     } else {         $img.removeclass('rotate');     } }); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -