我创建了一个jQuery脚本(带帮助)但效果很好但是我需要它来自动化/动画本身而不使用click功能,我只是想知道这是否可能,如果是这样,怎么样?与幻灯片放映类似。
基本上,代码允许我点击图像并隐藏/显示DIV,同时更改元素列表,例如class / id name。
这是我的代码:
JQUERY:
jQuery(document).ready(function(){
//if this is not the first tab, hide it
jQuery(".imgs:not(:first)").hide();
//to fix u know who
jQuery(".imgs:first").show();
//when we click one of the tabs
jQuery(".img_selection a").click(function(){
//get the ID of the element we need to show
stringref = jQuery(this).attr("href").split('#')[1];
// adjust css on tabs to show active tab
$('.img_selection a').removeAttr('id'); // remove all ids
$(this).attr('id', this.className + "_on") // create class+_on as this id.
//hide the tabs that doesn't match the ID
jQuery('.imgs:not(#'+stringref+')').hide();
//fix
if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0") {
jQuery('.imgs#' + stringref).show();
} else
//display our tab fading it in
jQuery('.imgs#' + stringref).show();
//stay with me
return false;
});
});
答案 0 :(得分:2)
这应该这样做。它获得所有“标签”并按循环顺序点击,每次点击之间暂停2秒(2000毫秒)
var tabs = jQuery(".img_selection a");
var len = tabs.size();
var index = 1;
function automate() {
tabs.eq((index%len)).trigger('click');
index++;
}
var robot = setInterval(automate, 2000);
//if at some point you want to stop the automation just call
clearInterval(robot);
制作演示
答案 1 :(得分:1)
Time-limiting a function execution is not possible in Javascript.
但是,HTML5带来了web-workers,它们基本上是后台 worker 线程。在一段时间后,suspend网络工作者可能会成功。