I'm trying to fade out a div, then fade in another div, and that works for me, the problem is I'm not able to delay it, so first div doesn't push the other div down...
This is my HTML (everything is inline):
<!doctype html>
<html>
<head>
<title>JavaScript popup</title>
<meta charset="utf-8">
<script src=".12.0/jquery.min.js"></script>
<script src="main.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){
$(".main").hide();
});
$("#continue-button").click(function(){
$(".vge-eksponering").hide();
$(".main").show();
});
</script>
<body style="background-color:lightgrey;">
<div class="vge-eksponering" style="text-align:center;">
<h1>Tjek VGEs hjemmeside ud på:
<br>
<a href="" target="_blank">www.vge.dk</a></h1>
<button id="continue-button" style="font-size:2em;">Fortsæt til VGE News</button>
</div>
<script>
$("#continue-button").click(function(){
$(".vge-eksponering").fadeOut(1200);
$(".main").fadeIn(1200);
});
</script>
<div class="main" style="background-color:lightblue;">
<h1>JavaScript popup</h1>
<p>Hopefully this will work soon...</p>
</div>
</body>
</html>
I'm trying to fade out a div, then fade in another div, and that works for me, the problem is I'm not able to delay it, so first div doesn't push the other div down...
This is my HTML (everything is inline):
<!doctype html>
<html>
<head>
<title>JavaScript popup</title>
<meta charset="utf-8">
<script src="https://ajax.googleapis./ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="main.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){
$(".main").hide();
});
$("#continue-button").click(function(){
$(".vge-eksponering").hide();
$(".main").show();
});
</script>
<body style="background-color:lightgrey;">
<div class="vge-eksponering" style="text-align:center;">
<h1>Tjek VGEs hjemmeside ud på:
<br>
<a href="http://www.vge.dk" target="_blank">www.vge.dk</a></h1>
<button id="continue-button" style="font-size:2em;">Fortsæt til VGE News</button>
</div>
<script>
$("#continue-button").click(function(){
$(".vge-eksponering").fadeOut(1200);
$(".main").fadeIn(1200);
});
</script>
<div class="main" style="background-color:lightblue;">
<h1>JavaScript popup</h1>
<p>Hopefully this will work soon...</p>
</div>
</body>
</html>
EDIT: I used this, and it worked.
$(".vge-eksponering").fadeOut(1200);
$(".main").delay(1200).fadeIn(1200);
.vge-eksponering
and, when it's done fading out, fade in .main
?
– T.J. Crowder
Commented
Feb 4, 2016 at 18:19
You have (at least) two choices:
If there's only one .vge-eksponering
element, then use the pletion callback fadeOut
gives you:
$(".vge-eksponering").fadeOut(1200, function() {
$(".main").fadeIn(1200);
});
Or just use delay
with a value equivalent to the first fadeOut:
$(".vge-eksponering").fadeOut(1200);
$(".main").delay(1200).fadeIn(1200);
use setInterval
setInterval(function() {
$(".main").fadeIn(1200);
}, 1200);
a tutorial on setInterval
http://www.w3schools./jsref/met_win_setinterval.asp