2017-04-19 2 views
0

jQueryスライダーを作成しようとしています。 各スライドには、スライドがアクティブなときにフェードインしなければならないさまざまな要素があり、次のスライドに行くときにフェードアウトする必要があります。jQueryのアニメーションスライダー

これまでのところ、スライドがフェードインしますが、問題はスライダをループさせることができないということです。

のjQueryコード:

function slider() { 
    $(".animate-circle-1").delay(1000).fadeIn(1000).delay(6000).fadeOut(1000).delay(12000).fadeIn(1000); 
    $(".animate-quote-0").delay(2000).fadeIn(1000).delay(2000).fadeOut(1000).delay(15000).fadeIn(1000); 
    $(".animate-person-1").delay(5000).fadeIn(1000).delay(2000).fadeOut(1000); 
    $(".animate-quote-1").delay(5000).fadeIn(1000).delay(2000).fadeOut(1000); 
    $(".animate-person-2").delay(9000).fadeIn(1000).delay(4000).fadeOut(1000); 
    $(".animate-circle-2").delay(10000).fadeIn(1000).delay(3000).fadeOut(1000); 
    $(".animate-quote-2").delay(11000).fadeIn(1000).delay(2000).fadeOut(1000); 
    $(".animate-person-3").delay(15000).fadeIn(1000).delay(4000).fadeOut(1000); 
    $(".animate-circle-3").delay(16000).fadeIn(1000).delay(3000).fadeOut(1000); 
    $(".animate-quote-3").delay(17000).fadeIn(1000).delay(2000).fadeOut(1000); 
    $(".slide-1").delay(8000).fadeOut(2000); 
    $(".slide-2").delay(8000).fadeIn(2000); 
    $(".slide-2").delay(6000).fadeOut(2000); 
    $(".slide-3").delay(6000).fadeIn(2000); 
} 

HTML:

<div class="header-wrapper"> 

    <div class="slide slide-1"> 
    </div> 

    <div class="slide slide-2"> 
    </div> 

    <div class="slide slide-3"> 
    </div> 

    <div class="header-wrapper-elements"> 
    <div class="slide-container"> 
     <div class="animate-quote animate-quote-0" style="display: none;">“It’s<br> 
     good<br> 
     to<br> 
     connect”</div> 
     <div class="animate-person animate-person-1" style="display: none;"></div> 
     <div class="animate-circle animate-circle-1" style="display: none;"></div> 
     <div class="animate-quote animate-quote-1" style="display: none;">Creëer<br> 
     betrokken-<br> 
     heid in de<br> 
     student<br> 
     levenscyclus</div> 
     <div class="animate-person animate-person-2" style="display: none;"></div> 
     <div class="animate-circle animate-circle-2" style="display: none;"></div> 
     <div class="animate-quote animate-quote-2" style="display: none;">bouw<br> 
     relaties om<br> 
     business te<br> 
     creëren</div> 
     <div class="animate-person animate-person-3" style="display: none;"></div> 
     <div class="animate-circle animate-circle-3" style="display: none;"></div> 
     <div class="animate-quote animate-quote-3" style="display: none;">Bied een<br> 
     unieke<br> 
     klant-<br> 
     ervaring</div> 
    </div> 
    </div> 

誰かが良い解決策を知っていますか?

答えて

0

あなたのHMTLとJSの建築家はあまり良くありません。あなたはそれをより良くする方法を見るためにhttps://www.sitepoint.com/web-foundations/making-simple-image-slider-html-css-jquery/を見ることができます。 注:画像を変更するためには、あなたのマウス

`

<!-- Some junk --> 
<div class="content"> 
    <p>This is a proof-of-concept for a slideshow that doesn't use any Javascript. It does not have pages or left/right buttons etc. 
    <ul> 
    <li>Pick a static width and height for the slides.</li> 
    <li>Place all your slides side-by-side in a <strong>single</strong> image.</li> 
    <li>Set the image as the background of the div. Use the background-position property to set the initial position of 0px. Be sure to calculate where the position needs to be for each slide, they will be negative numbers.</li> 
    <li>In the animation CSS, set the length of time for the entire slideshow to run. For my three images I used 13 seconds. If you have more images you will need to increase this as needed.</li> 
    <li>For the keyframes, you need to do some math. It's (pics * 2)/100. Use this as the multipler for each slide, with "100%" being the last keyframe. Each image needs to have multiple keyframes in order for the slideshow to "pause" on that image. I used two stops for each slide, hence "pics * 2". Notice how the last keyframe at 100% is also the position of the first image of the slideshow. So technically, the first image gets 3 keyframes. I hope this makes sense. 
    <li>This project is using Codepen's built-in -prefix-free setting, otherwise you need all those prefixes too!</li> 
    <li>The Javascript is optional and is only there to enable clicking on each banner. If you want, you can remove all that and use a click event just on the div itself (one link for the entire slideshow). You will have to calculate the range of positions you want to be enabled for each banner click event. For example on the first banner, it is only clickable until it scrolls about half way to the 2nd banner, then the click fires on the second banner.</li> 
    </ul> 
    </p> 

<p>Images taken from random Lorempixel.com images.</p> 
</div>` 



    /* USUAL STUFF */ 
body { margin:10px auto; text-align:center; } 
.content { max-width:800px;text-align:left; margin:auto; } 

/* THE DIV */ 
.simple-ss { 
    width:800px; 
    height:250px; 
    background-color:red; 
    margin:auto; 
    background-image:url("http://imgur.com/download/OtK7XDW"); 
    background-position:0; 
    background-repeat:no-repeat; 
    background-size:cover; 

/* ANIMATING STUFF */ 
    animation-name: slide; 
    animation-duration: 13s; 
    animation-direction: normal; 
    animation-timing-function: ease; 
    animation-iteration-count: infinite; 
} 

/* NOTE CODEPEN AUTOGENERATING -PREFIXES */ 
@keyframes slide { 
    0% {background-position:0 0;} 
    16.66% {background-position:0 0;} 
    33.32% {background-position:-800px 0;} 
    49.98% {background-position:-800px 0;} 
    66.64% {background-position:-1600px 0;} 
    83.30% {background-position:-1600px 0;} 
    100% {background-position:0 0;} 
} 
el = document.getElementById("simple-ss"); 

el.onclick =リンクをスライドさせ、

function links(){ left = parseInt(getComputedStyle(el).getPropertyValue( "background-position")。split( ""、1));

/* */ 場合(左> = -1200){

// Second when half way scrolled either side 
alert("second"); 
//window.open("http://www.google.com"); 

}そうでなければ(左> = -400){

// First until about half way scrolled over 
alert("first"); 
//window.open("http://www.google.com"); 

}そうならCLICKイベントの位置を規定場合{

// Third when over half way into banner 
alert("third"); 
//window.open("http://www.google.com"); 

}

(> = -1600を左)

}

関連する問題