我如何调用这个函数 onLoad 到一个 url?
function fadeLoop() {
var counter = 0,
divs = $('.fader').hide(),
dur = 500;
function showDiv() {
divs.fadeOut(dur) // hide all divs
.filter(function(index) {
return index == counter % divs.length;
}) // figure out correct div to show
.delay(dur) // delay until fadeout is finished
.fadeIn(dur); // and show it
counter++;
}; // function to loop through divs and show correct div
showDiv(); // show first div
return setInterval(function() {
showDiv(); // show next div
}, 5 * 1000); // do this every 5 seconds };
$(function() {
var interval;
$("#start").click(function() {
if (interval == undefined){
interval = fadeLoop();
$(this).val("Stop");
}
else{
clearInterval(interval);
$(this).val("Start");
interval = undefined;
}
}); });
这个函数激活了我的交互式工具提示;但是,我不知道怎么调用它,而且我需要把它放在标题或页面中吗?脚本在页面上,链接在页眉上……想法?
提前致谢。
克里斯
最佳答案
像这样调用函数:
$(document).ready(function(){
fadeLoop()
});
Edit
看起来该功能是由点击事件激活的?为什么不将上面的内容更改为:
$(document).ready(function(){
$('#start').trigger('click');
});
关于javascript - 需要在javascript onload中调用这个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13652409/