javascript - JQuery, CSS and hover tag re-code -
.social-icon-holder { float: left; padding-left: 10px; } .social-icon { width: 40px; height: 40px; font-size: 30px; text-decoration: none; cursor: pointer; text-align: center; line-height: 40px; position: relative; -moz-transition: 0.5s; -o-transition: 0.5s; -webkit-transition: 0.5s; transition: 0.5s; /* background: #000;*/ color: #fff; float: left; -moz-border-radius: 100%; -webkit-border-radius: 100%; border-radius: 100%; border: 3px solid #fff; } .social-icon:hover { color: #fff; -moz-transform: rotatey(-180deg); -webkit-transform: rotatey(-180deg); transform: rotatey(-180deg); } .social-icon:hover .front { -moz-backface-visibility: hidden; -webkit-backface-visibility: hidden; backface-visibility: hidden; } .social-icon:hover .back { -moz-backface-visibility: visible; -webkit-backface-visibility: visible; backface-visibility: visible; } .social-icon .front, .social-icon .back { width: 40px; height: 40px; position: absolute; -moz-border-radius: 100%; -webkit-border-radius: 100%; border-radius: 100%; -moz-backface-visibility: visible; -webkit-backface-visibility: visible; backface-visibility: visible; } .social-icon .back { -moz-transform: rotatey(-180deg); -webkit-transform: rotatey(-180deg); transform: rotatey(-180deg); -moz-backface-visibility: hidden; -webkit-backface-visibility: hidden; backface-visibility: hidden; } .social-icon .twitter .back { background: #00aced; }
<div class="social-icon-holder"> <div class="social-icon"> <div class="twitter"> <div class="front">t</div> <div class="back">t</div> </div> </div> </div>
jsfiddle here
i did not produce majority of code.
the icon flips/rotates when user hovers on icon. realize done via hover
class.
however trigger animation manually (via event etc).
i understand not possible trigger hover
not trusted event.
can me re-code animation triggered via jquery?
in css set hover states, add selector same specific class. in example added class hover
, line .social-icon:hover
becomes .social-icon:hover, .social-icon.hover
etc.
you can toggle class using jquery's .toggleclass()
function.
in below example using button , click
event.
i added background color icon more visible, has nothing actual answer ;)
$('#triggerhover').on('click', function() { $('.social-icon').toggleclass('hover'); });
body { background: #ccc; } .social-icon-holder { float: left; padding-left: 10px; } .social-icon { width: 40px; height: 40px; font-size: 30px; text-decoration: none; cursor: pointer; text-align: center; line-height: 40px; position: relative; -moz-transition: 0.5s; -o-transition: 0.5s; -webkit-transition: 0.5s; transition: 0.5s; /* background: #000;*/ color: #fff; float: left; -moz-border-radius: 100%; -webkit-border-radius: 100%; border-radius: 100%; border: 3px solid #fff; } .social-icon:hover, .social-icon.hover { color: #fff; -moz-transform: rotatey(-180deg); -webkit-transform: rotatey(-180deg); transform: rotatey(-180deg); } .social-icon:hover .front, .social-icon.hover .front { -moz-backface-visibility: hidden; -webkit-backface-visibility: hidden; backface-visibility: hidden; } .social-icon:hover .back, .social-icon.hover .back { -moz-backface-visibility: visible; -webkit-backface-visibility: visible; backface-visibility: visible; } .social-icon .front, .social-icon .back { width: 40px; height: 40px; position: absolute; -moz-border-radius: 100%; -webkit-border-radius: 100%; border-radius: 100%; -moz-backface-visibility: visible; -webkit-backface-visibility: visible; backface-visibility: visible; } .social-icon .back { -moz-transform: rotatey(-180deg); -webkit-transform: rotatey(-180deg); transform: rotatey(-180deg); -moz-backface-visibility: hidden; -webkit-backface-visibility: hidden; backface-visibility: hidden; } .social-icon .twitter .back { background: #00aced; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="social-icon-holder"> <div class="social-icon"> <div class="twitter"> <div class="front">t</div> <div class="back">t</div> </div> </div> </div> <button id="triggerhover">click me!</button>
Comments
Post a Comment