Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="half">
  <ul>
    <li>Mouseenter to rotate by -45°.</li>
    <li>Mouseleave to rotate back to 0°.</li>
    <li>Click to start rotation from the current possition (-45°) to final position which is a full turn + 270°.</li>
    <li>From this point, if user mouseleave, add 45° to reach the "visual 0°", else, keep the possition.</li>
    <li>From this point, if user mouseenter, add 45°.</li>
    <li>On second click, animate in the oposite direction.</li>
    <li>From this point, if user mouseleave, remove 45° to reach the "visual 0°", else, keep the possition.</li>
    <li>If the user mouseenter or mouseleave while a click have been made (class .taz_isRunning is set), the animation will end to a "visual 0°" rather than -45° or 45°.</li>
    <li>If the user clicks twice before the end of a animation, then the animation visualy reverse.</li>
  </ul>
</div>
<div class="half last">
  <div class="cog"></div>
  <div class="cog fa fa-cog"></div>
</div>
              
            
!

CSS

              
                $size: 200px;
body {
	display: flex;
}
.half {
	width: 50%;
	&.last {
		text-align: center;
	}
}
.cog {
	display: inline-block;
	width: $size;
	height: $size;
	cursor: pointer;
	position: relative;
	&:not(.fa){
		background-color: black;
		border-radius: 50%;
		&:before {
			content: '';
			height: $size/2;
			width: 2px;
			background-color: white;
			position: absolute;
			left: $size/2;
		}
		&:after {
			content: '';
			width: 20px;
			height: 20px;
			background-color: white;
			border-radius: 50%;
			position: absolute;
			top: 5px;
			left: ($size/2 - 9px);
		}
	}
	&.fa {
		margin-left: 100px;
		&:before {
			font-size: 230px;
			line-height: 200px;
			position: absolute;
			left: 0;
		}
	}
}

ul {
	width: 50%;
}
              
            
!

JS

              
                var
	cog				= $('.cog'),
	overAngle		= 45,
	clickedAngle	= 360-overAngle*2+360;

function taz_cogTween(fromValue, toValue){ // Mouseenter/mousleave basic tween.
	TweenMax.fromTo(cog, 0.5, {
		rotationZ: fromValue
	}, {
		rotationZ: toValue,
		ease: Power4.easeOut
	});
}
function taz_cogTween2(toValue){ // Tween upon click. This one handles add/removing necessary CSS classes.
	TweenMax.to(cog, 2, {
		rotationZ: toValue,
		ease: Power4.easeOut,
		onStart: function(){
			cog.addClass('taz_isRunning'); // Each time the user clicks, we add this class. It's present at the animation begins.
		},
		onComplete: function(){
			cog.removeClass('taz_isRunning');
			if (cog.hasClass('taz_isRunningIn')){ // The class taz_isTriggered is set only for one way (first click, 3th, 5th, etc. click)
				cog.addClass('taz_isTriggered'); 
			} else {
				cog.removeClass('taz_isTriggered');
			}
		}
	});
}

cog.on('mouseenter', function(){
	var
		isRunningIn	= cog.hasClass('taz_isRunningIn'),
		isRunning	= cog.hasClass('taz_isRunning'),
		isTriggered	= cog.hasClass('taz_isTriggered');

	if (!isRunningIn && !isTriggered){ // Initial mouseenter
		taz_cogTween(0, -overAngle);
	} else if (isRunningIn && !isTriggered){ // Entering while cogTween2 is runningIn
		taz_cogTween2(-(overAngle+clickedAngle));
	} else if (isRunningIn && isTriggered){ // Entering when cogTween2 animation is complete
		taz_cogTween(-(overAngle+clickedAngle+overAngle), -(overAngle+clickedAngle));
	} else if (isTriggered && isRunning){ // Entering while cogTween2 is running back
		taz_cogTween2(-overAngle);
	}
});
cog.on('mouseleave', function(){
	var
		isRunningIn	= cog.hasClass('taz_isRunningIn'),
		isRunning	= cog.hasClass('taz_isRunning'),
		isTriggered	= cog.hasClass('taz_isTriggered');

	if (!isRunningIn && !cog.hasClass('taz_isTriggered')){ // Initial mouseleave
		taz_cogTween(-overAngle, 0);
	} else if (isRunningIn && !isTriggered){ // Leaving while cogTween2 is runningIn
		taz_cogTween2(-(overAngle+clickedAngle+overAngle));
	} else if (isRunningIn && isTriggered){ // Leaving when cogTween2 animation is complete
		taz_cogTween(-(overAngle+clickedAngle), -(overAngle+clickedAngle+overAngle));
	} else if (isTriggered && isRunning){ // Leaving while cogTween2 is running back
		taz_cogTween2(0);
	}
});

cog.click(function(event){
	event.preventDefault();
	var
		isRunningIn	= cog.hasClass('taz_isRunningIn'),
		isTriggered	= cog.hasClass('taz_isTriggered');

	if (!isRunningIn && !isTriggered){ // Initial click --> runningIn
		taz_cogTween2(-(overAngle+clickedAngle));
	} else if (isRunningIn){ // Clicking while cogTween2 is runningIn
		taz_cogTween2(-overAngle);
	} else if (isTriggered){ // Clicking when cogTween2 animation is complete
		taz_cogTween2(-(overAngle+clickedAngle));
	}
	cog.toggleClass('taz_isRunningIn');
});


// var
//     wheel	= $('.wheel'),
//     durationA = 0.2,
//     durationB = 2,
//     tlCCW = new TimelineMax(),
//     tlCW = new TimelineMax(),
//     activeTween = tlCCW.tweenTo(0),
//     tweenA = TweenMax.to(wheel, durationA, {
//       rotationZ: -45,
//       ease: Power0.easeOut
//     }),
//     tweenB = TweenMax.to(wheel, durationB, {
//       rotationZ: '-=' + (360 + 270),
//       ease: Power4.easeOut
//     }),
//     tweenC = TweenMax.to(wheel, durationA, {
//       rotationZ: '-=' + 45,
//       ease: Power0.easeOut
//     }),
//     tweenD = TweenMax.to(wheel, durationA, {
//       rotationZ: 45,
//       ease: Power0.easeOut
//     }),
//     tweenE = TweenMax.to(wheel, durationB, {
//       rotationZ: '+=' + (360 + 270),
//       ease: Power4.easeOut
//     }),
//     tweenF = TweenMax.to(wheel, durationA, {
//       rotationZ: '+=' + 45,
//       ease: Power0.easeOut
//     });

// tlCCW.add(tweenA);
// tlCCW.add(tweenB);
// tlCCW.add(tweenC);
// tlCW.add(tweenD);
// tlCW.add(tweenE);
// tlCW.add(tweenF);
// tlCCW.pause();
// tlCW.pause();

// wheel.on('mouseover', function(){
//   wheel.addClass('taz_isOver');
//  if (!activeTween.isActive()){
//     if (!wheel.hasClass('taz_isTriggered')){
//       tlCCW.tweenTo(durationA);
//     } else {
//       tlCCW.tweenTo(durationA + durationB);
//     }
//   }
// });
// wheel.on('mouseout', function(){
//   wheel.removeClass('taz_isOver');
//   if (!activeTween.isActive()){
//     if (!wheel.hasClass('taz_isTriggered')){
//       tlCCW.tweenTo(0);
//     } else {
//       tlCCW.tweenTo(durationA + durationB + durationA);
//     }
//   }
// });

// wheel.click(function(event){
// 	event.preventDefault();
//   if (!wheel.hasClass('taz_isTriggered')){
//     tlCCW.seek(durationA);
//     activeTween = tlCCW.tweenTo(durationA + durationB, {
//       onComplete: function(){
//         wheel.addClass('taz_isTriggered');
//         if (!wheel.hasClass('taz_isOver')){
//           tlCCW.tweenTo(durationA + durationB + durationA);
//         }
//       }
//     });
//   } else {
//      tlCW.seek(durationA);
//      activeTween = tlCW.tweenTo(durationA + durationB, {
//       onComplete: function(){
//         wheel.removeClass('taz_isTriggered');
//         tlCCW.seek(durationA);
//         if (!wheel.hasClass('taz_isOver')){
//           tlCW.tweenTo(durationA + durationB + durationA);
//         }
//       }
//     });
//   }
// });
              
            
!
999px

Console