简体   繁体   English

如何使JavaScript滑块自动滑动

[英]How to make javascript slider automatically slide

My javascript skills are pretty basic but I'm trying to learn more, so was wondering if someone could help me out or point me in the right direction as I'm a bit puzzled with a site I'm working on. 我的JavaScript技能很基础,但是我想学习更多,所以想知道是否有人可以帮助我或向正确的方向指出我,因为我对正在工作的网站有些困惑。

The site is: http://epaints.co.uk/ basically I am trying to get the home page slider to slide automatically on page load, at the moment it only slides when the user clicks the navigation buttons. 该站点是: http : //epaints.co.uk/基本上,我试图让主页滑块在页面加载时自动滑动,此刻它仅在用户单击导航按钮时才滑动。

$('.caro-arrow.caro-arrow-r').click( function () {
    setTimeout("$('.caro-arrow.caro-arrow-r').click()", 4000);
});

I always thought it was a simple as adding the below code for it to auto slide, but it doesn't seem to work: 我一直认为这很简单,只需为其添加以下代码即可自动滑动,但似乎不起作用:

  auto: true,
  autoControls: true

Like I said, if anyone can help me out or point me in the right direction, it would be greatly appreciated! 就像我说的,如果有人可以帮助我或指出正确的方向,将不胜感激!

Thanks for your help :-) 谢谢你的帮助 :-)

Use the following code in your $(document).ready(function () { /* HERE */ }) $(document).ready(function () { /* HERE */ })使用以下代码

$('.caro-arrow.caro-arrow-r').click( function () {
    setTimeout("$('.caro-arrow.caro-arrow-r').click()", 4000);
}).trigger('click');

We don't need to write the same function twice, just trigger click so that it runs on page load. 我们不需要编写两次相同的函数,只需触发点击即可在页面加载时运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM