gpt4 book ai didi

JQuery,在 jsfiddle 中工作但不在现场的 li 元素的淡入循环

转载 作者:行者123 更新时间:2023-12-01 00:28:01 25 4
gpt4 key购买 nike

我有以下代码在 jsfiddle 中工作:http://jsfiddle.net/S5Cjm/1242/

function InOut(elem) {
var delayOn = 2000, // time each <li> should be visible
delayOff = 0, // time between revealing each <li>
fade = 1000; // fade duration

// Pause, fade in, pause again, fadeout, then fire the callback
elem.delay(delayOff).fadeIn(fade).delay(delayOn).fadeOut(function() {
// If we're not on the last <li>
if (elem.next().length > 0) {
// Call InOut on the next <li>
InOut(elem.next());
}
else {
// Else go back to the start
InOut(elem.siblings(':first'));
}
});
}

$(function() {
// Hide all the li's
$('#content li').hide();
// Call InOut to loop through them
InOut($('#content li:first'));
});

​但是,当嵌入到我的代码中时,它不起作用。

我在脑海中引用了 JQuery:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

它曾经莫名其妙地工作过,尽管复制了代码,但又没有再工作。

非常感谢任何帮助!

最佳答案

这对我有用:=)你的代码没有任何问题,只是你忘了将它包装在 $(document).ready(function(){});

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<meta name="author" content=""/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<title></title>
<style type="text/css">
*{margin:0px;padding:0px}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
//alert('workin');
function InOut(elem) {
var delayOn = 2000, // time each <li> should be visible
delayOff = 0, // time between revealing each <li>
fade = 1000; // fade duration

// Pause, fade in, pause again, fadeout, then fire the callback
elem.delay(delayOff).fadeIn(fade).delay(delayOn).fadeOut(function() {
// If we're not on the last <li>
if (elem.next().length > 0) {
// Call InOut on the next <li>
InOut(elem.next());
}
else {
// Else go back to the start
InOut(elem.siblings(':first'));
}
});
}

$(function() {
// Hide all the li's
$('#content li').hide();
// Call InOut to loop through them
InOut($('#content li:first'));
});
});
</script>
</head>
<body>
<ul id="content">
<li>first</li>
<li>second</li>
<li>third</li>
<li>fourth</li>
<li>fifth</li>
<li>sixth</li>
</ul>
</body>
</html>

关于JQuery,在 jsfiddle 中工作但不在现场的 li 元素的淡入循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13571777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com