最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - How to make jquery slider to start afresh

programmeradmin0浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I would want to have the below setinterval() to start afresh once the last slide is reached, am having three div and but the slide stops once it reaches the third div, i would want it to start again from the first.

My Html code

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="jquery.min.js"></script>
<script src="myjava.js"></script>
</head>
<body>
<div class="container">
<div id="slide1" class="slider1">My first slide goes here</div>
<div id="slide2" class="slider2">My second slide goes here</div>
<div id="slide3" class="slider3">My third slide goes here</div>

And my Java code Below

jQuery(function($){ 

var currentDIV = $("#slide1");
var nextDIV, count = 1;
var myInterval = setInterval(function(){
    currentDIV.hide();
    currentDIV = currentDIV.next();
    currentDIV.show();


}, 2000);

});
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I would want to have the below setinterval() to start afresh once the last slide is reached, am having three div and but the slide stops once it reaches the third div, i would want it to start again from the first.

My Html code

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="jquery.min.js"></script>
<script src="myjava.js"></script>
</head>
<body>
<div class="container">
<div id="slide1" class="slider1">My first slide goes here</div>
<div id="slide2" class="slider2">My second slide goes here</div>
<div id="slide3" class="slider3">My third slide goes here</div>

And my Java code Below

jQuery(function($){ 

var currentDIV = $("#slide1");
var nextDIV, count = 1;
var myInterval = setInterval(function(){
    currentDIV.hide();
    currentDIV = currentDIV.next();
    currentDIV.show();


}, 2000);

});
Share Improve this question asked Jun 11, 2020 at 17:10 pandglobalpandglobal 431 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

HTML

<div class="container" id="slider-container">  
    <div id="slide1" class="slider-slide">My first slide goes here</div>
    <div id="slide2" class="slider-slide">My second slide goes here</div>
    <div id="slide3" class="slider-slide">My third slide goes here</div>
</div>

Javascript

( function( $ ){ 

    let firstDIV = currentDIV = $( '#slider-container div' ).first();

    if( firstDIV.length > 0 ){
        setInterval( () => {
            currentDIV = currentDIV.hide().next();

            if( currentDIV.length === 0 )
                currentDIV = firstDIV;

            currentDIV.show();

        }, 2000);
    }

} )(jQuery, undefined);
发布评论

评论列表(0)

  1. 暂无评论