2013-11-01 87 views
0

我已经包括了工作的网站即时通讯内的手风琴,一个内容区域包括YouTube视频,我已经成功地管理在另一个手风琴头选择拜堆栈溢出停下来,但是我有麻烦了解它的实际功能。我是相当新的jQuery和想了解如何工作,以实现未来的脚本。很难理解jQuery代码

任何帮助将不胜感激,Jquery的如下所示。

感谢,

梅丽莎

$(".accordion h3").eq(40).addClass("active"); 
$(".accordion div").eq(40).show(); 
$(".accordion h3").click(function(){ 
    var video = $(".accordion h3.active").next().children(); 
    var src = video.attr("src"); 
    video.attr("src",""); 
    video.attr("src",src); 

    $(this).next("div").slideToggle("slow") 
    .siblings("div").slideUp("slow"); 
    $(this).toggleClass("active"); 
    $(this).siblings("h3").removeClass("active"); 
}); 
+1

上面提到的每个选择器和方法都包含在[文档](http://api.jquery.com/)中。 [有教程(http://learn.jquery.com/)为好。 –

回答

0

我在这里加了一些解释性意见,并希望这会帮助你。

$(".accordion h3").eq(40).addClass("active"); 
$(".accordion div").eq(40).show(); 
$(".accordion h3").click(function(){ 
    var video = $(".accordion h3.active").next().children(); // Find the div containing the video 

    // The following three lines are a hack to stop the video. 
    var src = video.attr("src"); // Get the source of the video 
    video.attr("src",""); // Set the source to "" 
    video.attr("src",src); // Set the source back to the original source. 

    // Find the next div and toggle its state (sliding animation) while sliding up other divs (animated) 
    $(this).next("div").slideToggle("slow") 
    .siblings("div").slideUp("slow"); 

    // and toggle this one's active state 
    $(this).toggleClass("active"); 

    // while making the others inactive 
    $(this).siblings("h3").removeClass("active"); 
}); 
+0

谢谢你这么多的基督徒,现在我看到这些,它更有道理!再次感谢! –