Reputation: 47
After the header, I have a hidden div with a height transition that is activatable by a button, but while the page is loading, the browser shows the content of that div and afterwards hides it.
This is the script that I used:
$(document).ready(function(){
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function(){
$(".slidingDiv").slideToggle();
});
});
Is there's a way to avoid it?
I hope I was clear, thank you!
Upvotes: 1
Views: 84
Reputation: 2156
The problem is you're hiding the div at DOMready, wich occurs AFTER all content of the page has been loaded (and displayed)...
You must hide your div before that event. You're be better off using CSS hiding (display: none
) rather than JS.
Upvotes: -1
Reputation: 16027
This will work. Hide the div in css in the head tag (loaded first) then show it via javascript. If javascript isn't active, the noscript
tag will override the display property and show the div.
In the head :
<style type="text/css">
.slidingDiv{display: none;}
</style>
<noscript>
<style type="text/css">
.slidingDiv{display: block;}
</style>
</noscript>
<script type="text/javascript">
$(document).ready(function(){
$(".slidingDiv").css({"display":"block"});
}
</script>
Upvotes: 2
Reputation: 7658
<div class="slidingDiv" style="display: none;">Sliding Div</div>
<button class="show_hide">Show/Hide</button>
$(document).ready(function() {
$('.show_hide').click(function() {
$('.slidingDiv').slideToggle('fast');
});
});
Upvotes: 0
Reputation: 166
Try adding style="display: none;"
to <div class="slidingDiv">
...
Upvotes: 0