I'm using a basic jQuery accordion script (using jquery ui), and I'd like to have the area affect by the script first load then fade in (so there isn't a flashing of the images as they all load without jquery then the accordion folds up). What function do I need to add to the JS below to have fadeIn after load of that script (and #accordion and the images)?
Thanks, JG
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#accordion").accordion( {active: 2} );
});
</script>
<style>
#accordion {
margin: 0px 0 0;
width: 640px;
min-height: 650px;
float: left;
}
#accordion H2 {
background: #f8f7f5;
color: #582802;
border: 1px solid #cccccc;
cursor: pointer;
font: 12px Arial, Helvetica, sans-serif;
line-height: 16px;
margin: 0 0 4px 0;
padding: 9px 9px 9px 9px;
font-weight: bold;
}
</style>
<div id="accordion">
<h2>Click for Image 1</h2>
<div class="content">
<img src="img1.jpg">
</div>
<h2>Click for Image 2</h2>
<div class="content">
<img src="img2.jpg">
</div>
<h2>Click for Image 3</h2>
<div class="content">
<img src="img3.jpg">
</div>
</div>
Try to hide the accordion (display:none) and then fadeIn on document ready.
<div id="accordion" style="display:none;">...... </div>
$(document).ready(function(){
$("#accordion").fadeIn("slow");
$("#accordion").accordion( {active: 2} );
});
Hey check out the my JsFiddle.
http://jsfiddle.net/thewingser/qM5cD/8/
I believe this is what you wanted. Also I replaced your images with paragraphs just because jsfiddle can't resolve your pictures.
per request of Lokase
<html>
<head>
<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
window.onload = (function(){
try{
$(document).ready(function() {
$("#accordion").accordion();
});
}catch(e){}});
</script>
<style>
#accordion {
margin: 0px 0 0;
width: 640px;
min-height: 650px;
float: left;
}
#accordion H2 {
background: #f8f7f5;
color: #582802;
border: 1px solid #cccccc;
cursor: pointer;
font: 12px Arial, Helvetica, sans-serif;
line-height: 16px;
margin: 0 0 4px 0;
padding: 9px 9px 9px 9px;
font-weight: bold;
}
</style>
</head>
<body>
<script>
jQuery(document).ready(function(){
$('.accordion .head').click(function() {
$(this).next().toggle('slow');
return false;
}).next().hide();
});
</script>
<div id="accordion">
<h2>Click for Image 1</h2>
<div class="content">
<p>test</p>
</div>
<h2>Click for Image 2</h2>
<div class="content">
<p>test</p>
</div>
<h2>Click for Image 3</h2>
<div class="content">
<p>test</p>
</div>
</div>
</body>
</html>
try this:
Javascript
jQuery(document).ready(function ($) {
$("#accordion").accordion({ active: 1 })
});
function li() {
$(".content").fadeIn(500);
$("#accordion").accordion({ active: this })
}
HTML
<div id="accordion">
<a onclick="li();"><h2>Click for Image 1</h2></a>
<div class="content">
<img src="Image/cat.jpg" width="100px" height="100px">
</div>
<a onclick="li();"> <h2>Click for Image 2</h2></a>
<div class="content">
<img src="Image/catUblueUeyes.jpg" width="140px" height="140px">
</div>
<a onclick="li();"> <h2>Click for Image 3</h2></a>
<div class="content" >
<img src="Image/jquery.jpg" width="140px" height="140px">
</div>
fixed or percentage assigned to the images to avoid damaging the accordion
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.