jQuery UI #Accordion加载然后fadeIN ......怎么样?

时间:2012-07-19 16:32:14

标签: javascript jquery jquery-ui accordion fadein

我正在使用一个基本的jQuery手风琴脚本(使用jquery ui),我想让脚本首先加载然后淡入该区域(因此没有闪烁的图像,因为它们全部加载没有jquery然后手风琴折叠起来)。我需要在下面的JS中添加什么函数才能在加载该脚本后使用fadeIn(以及#accordion和图像)?

谢谢, 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>

3 个答案:

答案 0 :(得分:2)

尝试隐藏手风琴(显示:无),然后在文档就绪时淡出。

http://jsfiddle.net/nQ6Uv/3

<div id="accordion" style="display:none;">...... </div>

$(document).ready(function(){
    $("#accordion").fadeIn("slow");
    $("#accordion").accordion( {active: 2} );  
}); 

答案 1 :(得分:0)

嘿,看看我的JsFiddle。

http://jsfiddle.net/thewingser/qM5cD/8/

我相信这就是你想要的。我也用段落替换你的图像只是因为jsfiddle无法解析你的图片。

根据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>

答案 2 :(得分:0)

试试这个:

的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>




固定或分配给图像的百分比,以避免损坏手风琴