javascript - I want to make the icon spin back when click on outside -
this code used spin arrow head upward direction on click on icon .i want spin when click on out side of icon , want repeat processes when click on icon , click outside of icon.
<html> <head> <link rel="stylesheet" type="text/css" href="troll.css"> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="../project/bootstrap.min.css" /> <link rel="stylesheet" type="text/css" href="../project/style.css" /> <link rel="stylesheet" type="text/css" href="../project/font-awesome-4.2.0/css/font-awesome.min.css" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> function rotate(){ document.getelementbyid("me").classname="spinner fa fa-caret-down"; } </script> </head> <body> <i onclick="rotate()" id="me" class=" fa fa-caret-down "></i> </body> </html>
associated css:
.spinner { -webkit-animation:spin 0.5s linear 1; -moz-animation:spin 0.5s linear 1; animation:spin 0.5s linear 1; animation-fill-mode: forwards; } @keyframes spin { 0% { transform: rotate(0); } 100% { transform: rotate(180deg); } } -webkit-keyframes spin { 0% { transform: rotate(0); } 100% { transform: rotate(180deg); } }
try this
function rotate(e){ document.getelementbyid("me").classname="spinner in fa fa-caret-down"; e.stoppropagation(); } function resetrotation(){ document.getelementbyid("me").classname="spinner out fa fa-caret-down"; } document.addeventlistener('click', resetrotation);
.spinner { transition: 0.5s linear; } .spinner.in{ transform: rotate(180deg); } .spinner.out{ transform: rotate(0deg); }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css"> <i onclick="rotate(event)" id="me" class="spinner fa fa-caret-down "></i>
Comments
Post a Comment