难以理解Jquery代码

时间:2013-11-01 00:22:30

标签: jquery

我已经在一个网站中加入了一个手风琴,一个内容区域包含一个youtube视频,由于Stack溢出而我选择了另一个手风琴标题时我已成功设法停止,但是我无法理解它是如何实际的功能。我是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 个答案:

答案 0 :(得分: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");
});
相关问题