2017-04-19 205 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的建築師不太好。你可以看看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));

/* DEFINE對於點擊事件倉*/ 如果(左> = -400){

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

}否則如果(左> = -1200){

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

}否則如果(左> = -1600){

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

}

}