javascript - White icon disappeared after second click on mobile -
this how code works:
- when click icon, dropdown content fade in
- when click again, dropdown content fade out
my code working on desktop don't know why there problem on mobile. icon disappeared after second click.
hoping of provide me advice. thanks!
$(document).ready(function(){ $(".advanced_search a").click(function(){ $(".overlay_search").fadetoggle(200); var $this = $(this); if ($this.hasclass('advancedsearch_icon_active')) { $(".advanced_search a").removeclass('advancedsearch_icon_active').addclass('advancedsearch_icon'); } else if ($this.hasclass('advancedsearch_icon')) { $(".advanced_search a").removeclass('advancedsearch_icon').addclass('advancedsearch_icon_active'); } else { $(".advanced_search a").addclass("advancedsearch_icon"); } }); });
body{ background-color: #ccc; } .advancedsearch_icon{ background: url('https://image.ibb.co/fxuxfq/filter.png') no-repeat right 0; width: 20px; height: 20px; padding-left: 20px; } .advancedsearch_icon:hover, .advancedsearch_icon_active{ background: url('https://image.ibb.co/ky4opk/filter_hover.png') no-repeat right 0; width: 20px; height: 20px; padding-left: 20px; } .overlay_search { display:none; position:absolute; width:100%; background:#eeeeee; overflow:hidden; z-index:3; -webkit-box-shadow: 7px 7px 24px -8px rgba(18,17,12,0.5); -moz-box-shadow: 7px 7px 24px -8px rgba(0,0,0,0.5); box-shadow: 7px 7px 24px -8px rgba(18,17,12,0.5); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="advanced_search"> <a class="advancedsearch_icon" href="#"></a> </div> <div class="overlay_search"> content here. </div>
keep in mind on mobile devices there no :hover
event. can use :active
use after :hover
. example a:hover, a:active { styles }
. maybe causing problem
$(document).ready(function(){ $(".advanced_search a").click(function(){ $(".overlay_search").fadetoggle(200); var $this = $(this); if ($this.hasclass('advancedsearch_icon_active')) { $(".advanced_search a").removeclass('advancedsearch_icon_active').addclass('advancedsearch_icon'); } else if ($this.hasclass('advancedsearch_icon')) { $(".advanced_search a").removeclass('advancedsearch_icon').addclass('advancedsearch_icon_active'); } else { $(".advanced_search a").addclass("advancedsearch_icon"); } }); });
body{ background-color: #ccc; } .advancedsearch_icon{ background: url('https://image.ibb.co/fxuxfq/filter.png') no-repeat right 0; width: 20px; height: 20px; padding-left: 20px; } .advancedsearch_icon:hover, .advancedsearch_icon_active, .advancedsearch_icon:active { background: url('https://image.ibb.co/ky4opk/filter_hover.png') no-repeat right 0; width: 20px; height: 20px; padding-left: 20px; } .overlay_search { display:none; position:absolute; width:100%; background:#eeeeee; overflow:hidden; z-index:3; -webkit-box-shadow: 7px 7px 24px -8px rgba(18,17,12,0.5); -moz-box-shadow: 7px 7px 24px -8px rgba(0,0,0,0.5); box-shadow: 7px 7px 24px -8px rgba(18,17,12,0.5); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="advanced_search"> <a class="advancedsearch_icon" href="#"></a> </div> <div class="overlay_search"> content here. </div>
Comments
Post a Comment