JQuery 自动幻灯片

JQuery automatic slideshow

本文关键字:幻灯片 JQuery      更新时间:2023-09-26

我正在尝试在我的网页上使用JQuery实现一个简单的自动幻灯片。我遵循了本教程:https://www.youtube.com/watch?v=r5iPoJZjXnU。但是,似乎我的淡出()和淡入()函数不能很好地工作。代码有效,但图像之间的过渡太快且不平滑。

这是我所做的:

在我的头标签中添加了这些行,用于上传 jquery 和 jquery UI 库:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

然后,在我的身体标签的末尾,我简单地添加了:

<script type="text/javascript">
function galerie(){
        var active = $("#slideshow .active");
        var next = (active.next().length > 0) ? active.next() : $("#slideshow img:first");
        active.fadeOut(function(){
            active.removeClass("active");
        });
        next.fadeIn("slow").addClass("active");
    }
</script>

并在我单击我的 H1 标签时调用此函数:

<h1 onClick="galerie()">Pure</h1>

你有什么建议吗?

问题解决了,是我的 html 结构不正确