Javascript导航输出(缩小)
我有一个页面,输出以下内容 这是我的模板中的htmlJavascript导航输出(缩小),javascript,jquery,Javascript,Jquery,我有一个页面,输出以下内容 这是我的模板中的html <ul id="process"><span>Process: </span> 流程: 这是我的小型Javascript(functions.js) $(窗口)。加载(函数(){ 变量a=$(“#滑块”).children(“img”); currentIndex=0; slideCount=a.长度; 衰减率=1E3; 导航=$(“#进程”); navCnt=0; navNumFix=1; 用于(i=
<ul id="process"><span>Process: </span>
流程:
这是我的小型Javascript(functions.js)
$(窗口)。加载(函数(){
变量a=$(“#滑块”).children(“img”);
currentIndex=0;
slideCount=a.长度;
衰减率=1E3;
导航=$(“#进程”);
navCnt=0;
navNumFix=1;
用于(i=0;i
对于my slider,这一切都输出ul标记,并通过Javascript附加列表项,如下所示:
<ul id="process"><span>Process: </span>
<li><a href="#" class="navItem" data="0">1</a></li>
<li><a href="#" class="navItem" data="1">2</a></li>
</ul>
流程:
与在我的模板中输出ul标记不同,如何仅在脚本调用时输出ul标记?类似于上面的列表项。这应该可以…首先将模板置于“无显示”状态,然后在添加列表元素后显示它:
<ul style="display:none" id="process"><span>Process: </span></ul>
Javascript:
$(window).load(function () {
var a = $("#slider").children("img");
currentIndex = 0;
slideCount = a.length;
fadeDuration = 1E3;
navigation = $("#process");
navCnt = 0;
navNumFix = 1;
for (i = 0; i < slideCount; i++) navigation.append('<li><a href="#" class="navItem" data="' + navCnt+++'">' + navNumFix+++"</a></li> ");
$(".navItem").click(function () {
var b = $(this).attr("data"),
c = currentIndex;
currentIndex = b;
c != currentIndex && ($(a[c]).fadeOut(fadeDuration), $(a[currentIndex]).fadeIn(fadeDuration))
})
// Display the ul if there are slides
if(slideCount > 0)
navigation.show();
});
$(窗口)。加载(函数(){
变量a=$(“#滑块”).children(“img”);
currentIndex=0;
slideCount=a.长度;
衰减率=1E3;
导航=$(“#进程”);
navCnt=0;
navNumFix=1;
用于(i=0;i0)
navigation.show();
});
编辑:添加了仅当有幻灯片时才显示ul的条件不幸的是,这样做只是在加载时隐藏ul元素,然后即使没有要显示的列表项也会显示。好了,@Christopherburton谢谢你,比利。结果很好。
$(window).load(function () {
var a = $("#slider").children("img");
currentIndex = 0;
slideCount = a.length;
fadeDuration = 1E3;
navigation = $("#process");
navCnt = 0;
navNumFix = 1;
for (i = 0; i < slideCount; i++) navigation.append('<li><a href="#" class="navItem" data="' + navCnt+++'">' + navNumFix+++"</a></li> ");
$(".navItem").click(function () {
var b = $(this).attr("data"),
c = currentIndex;
currentIndex = b;
c != currentIndex && ($(a[c]).fadeOut(fadeDuration), $(a[currentIndex]).fadeIn(fadeDuration))
})
// Display the ul if there are slides
if(slideCount > 0)
navigation.show();
});