javascript - Animation to show / hide script using css -
i want add fade in / fade out effect hidden block (id = "help"). how can animate block using pure css? also, want animate link (id = "show) after clicking. please , give me examples.
see code:
var showelem = document.getelementbyid("show"); var hideelem = document.getelementbyid("hide"); var helpdiv = document.getelementbyid("help"); helpdiv.style.display = 'none'; hideelem.style.visibility = 'hidden'; showelem.onclick = function() { showelem.style.visibility = 'hidden'; hideelem.style.visibility = 'visible'; helpdiv.style.display = 'block'; }; hideelem .onclick = function() { hideelem.style.visibility = 'hidden'; showelem.style.visibility = 'visible'; helpdiv.style.display = 'none'; };
div#help { border: 1px solid black; height: 200px; width: 300px; padding: 10px; margin-top: 10px; }
<!doctype html> <html> <head> <meta charset=utf-8 /> <title>js bin</title> </head> <body> <a href="#" id="show">show</a> <a href="#" id="hide">hide</a> <div id="help"></div> </body> </html>
try this:
$(document).ready(function(){ $("#show").click(function(){ $('.help').addclass('sh'); $(this).css('opacity',0) $("#hide").css('opacity',1) }) $("#hide").click(function(){ $('.help').removeclass('sh'); $(this).css('opacity',0) $("#show").css('opacity',1) }) })
#hide, #show, .help { transition: 1s; } .help { border: 1px solid black; height: 200px; width: 300px; padding: 10px; margin-top: 10px; opacity: 0; } #hide { opacity: 0; } .sh { opacity: 1; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <a href="#" id="show">show</a> <a href="#" id="hide">hide</a> <div class="help" class="sh"></div>
Comments
Post a Comment