javascript - Display block after fadeout or fadein after fadeto -


when click on image want div fadein , fadeout. div should occupy same space (display: block). if click again, want div reappear.

can't achieve this. if use fadeout(), inline style display:none added. if use fadeto(), div hidden without occupying space.

how have it?

code:

function edit(oneid)  {    avisedit(oneid);    }    function avisedit(oneid)  {  	var nom = $('#x'+oneid+' .nom').text();  	showalerts("ara pots editar el valor dels camps de '"+nom+"'", 2);  }      function showalerts(sms, code)  {  	switch(code)  	{  		case 0:  			actions(sms, "success");  			break;  		  		case 1:  			actions(sms, "error");  			break;  		case 2:  			actions(sms, "info");  			break;  	}  }    function actions(sms, tipus)  {  	$("#warningboxes").toggleclass(tipus);	// add class  	$('#warningboxes').css('visibility','visible').hide();		// start hidden fadein  	$("#warningboxes").html(sms); // add message in div  	$("#warningboxes").fadein(1500, function() // show  		{  			settimeout(function()  			{  				$('#warningboxes').fadeout(1500, 0); // dissapears removes space of div #warningboxes; fadeto(), fadein won't work anymore  			}, 1500)  			  			  			settimeout(function()  			{  				backtostd(tipus);  // remove properties added still works  				  			}, 3000);  		}			  	);  }    function backtostd(tipus)  {  	$('#warningboxes').toggleclass(tipus);  	$('#warningboxes').css(  		{  			display: "block",  			opacity: "",  			filter: "",  			zoom: "",  			visibility: ""  		}  	);  }
.warningboxes  {  	border: 1px solid;  	margin: 10px 0px;  	padding:15px 10px 15px 50px;  	background-repeat: no-repeat;  	background-position: 10px center;  	visibility:hidden;  	display:block;  }  .info   {  	color: #00529b;  	background-color: #bde5f8;  	background-image: url('../res/pngicons/knobinfo.png');  }  .success   {  	color: #4f8a10;  	background-color: #dff2bf;  	background-image: url('../res/pngicons/knobvalidgreen.png');  }  .warning   {  	color: #9f6000;  	background-color: #feefb3;  	background-image: url('../res/pngicons/knobattention.png');  }  .error   {  	color: #d8000c;  	background-color: #ffbaba;  	background-image: url('../res/pngicons/knobcancel.png');  }
<body>    	<div class="warningboxes" id ="warningboxes" name="warningboxes"> info message</div>  	<table id="myid">        ....        ....        ...                <img src='./res/edit.png' id='imagenok4' class='deleteandothers' onclick='edit(4)'>        <img src='./res/edit.png' id='imagenok5' class='deleteandothers' onclick='edit(5)'>        <img src='./res/edit.png' id='imagenok6' class='deleteandothers' onclick='edit(6)'>        ....

adding code messy , irrelevant. important part in

function actions(sms, tipus) 

as here fadein , fadeout...

i have read lots can't make code work.

thanks!

please try code. on first click on img, div fades out. on clicking again, fades in.

update: if want div faded out initially, need add class gone manually @ start. because class causes div have 0 opacity.

$("#fade-img").on("click", function(e){    $("#fade-div").toggleclass("gone");  });//img click
#fade-div  {    background: green;    height: 200px;    transition: opacity 1s ease;    width: 200px;  }    #fade-div.gone  {    opacity: 0;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <img id="fade-img" src="http://placehold.it/100x100" alt="" />  <div id="fade-div" class="gone"></div>


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -