2017-12-08 251 views
8

, değeri aşağıdaki değişken $stepajax jquery ve php ile çoklu form sürecini nasıl canlandırırsınız? adımlar sayfasını güncellemek veya ferahlatıcı durumunda başlangıcına dönen önlemek için bir oturumda sayılır ve eklenen PHP ile

<?php 
    session_start(); 

    if (!empty($_SESSION['datos_form']['__step__'])) { 
    $step = $_SESSION['datos_form']['__step__']; 
    } else { 
    $step = '1'; 
    } 

?> 

Biz alma değeri vasıtasıyla elde edilir jQuery javascript kodundaki değişkenin. (Varsayılan değer aldığı için)

show_step(1); 

Daha önce de vurgulandığı gibi sürecin her adım, JavaScript koduna PHP alınan değere göre gösterilmiştir: eşit olacaktır

show_step(<?= $step; ?>); 

. gibi ek denetimler eklemek gerek olmadan

aşağıdadır:

current = $(this).parent(); 
next = $(this).parent().next(); 

Ben ajax uyarlamak için gerekiyor

https://jsfiddle.net/2LL8x1sm/

CSS ile aşağıdaki basit sihirbaz javascript kodu böylece adımı canlandırır.

geçerli kod zaten sprite adı verilen bir teknik kullanarak bir animasyon vardı

function animacion(caso){} 

enter image description here

Benim ihtiyacım sürecin animasyon adapte edebilmek ve gider bir simge (like this one) kullanarak etmektir

enter image description here

: aşağıdaki resme benzer ilerleme çubuğu

Bu animasyon geri bağlantıları ile birlikte çalışır ve devam aşağıdaki kodda fuction içinde bir örnek eklemek fonksiyonu animacion(caso) {} içine eklenmesi gerekir:

$(".test").animate({ "left": "-=50px" }, "slow"); 

Ve yürürlükte o testle, div çalışır sınıf, her adımda devam ederek sol stili değiştiriyordu.

Benim html kodunun css işlemini nasıl canlandırabilirim?

$(function() { 
 
    show_step(<?= $step; ?>);   
 
}); 
 

 
function animacion(caso){ 
 
    //$(".test").animate({ "left": "-=50px" }, "slow"); 
 
}; 
 

 
// function to save the form data and change the step 
 
function show_step(step){ 
 
    var data = $("#form").serialize(); 
 
    var url = 'saveTemp.php?step=' + step; 
 

 
    $.ajax({ 
 
     type: "POST", 
 
     url: url, 
 
     data: data 
 
    }) 
 
    .done(function(resp) { 
 
     $('.step').css("display", "none"); 
 
     $('#step'+step).fadeIn("slow"); 
 
     //animation of each step 
 
     animacion(step); 
 
    }); 
 
};
.container { 
 
    width: 100%; 
 
    padding-top: 20px; 
 
} 
 

 
.progressbar li { 
 
    list-style-type: none; 
 
    float: left; 
 
    width: 33.33%; 
 
    position: relative; 
 
    text-align: center; 
 
} 
 

 
.progressbar li > * { 
 
    position: relative; 
 
    padding-bottom: 20px; 
 
    display: inline-block; 
 
    font-size: 1.4rem; 
 
    color: #2c3f4c; 
 
    top: -45px; 
 
} 
 

 
.progressbar li:before { 
 
    content: ''; 
 
    width: 12px; 
 
    height: 12px; 
 
    display: block; 
 
    text-align: center; 
 
    margin: 0 auto; 
 
    border-radius: 50%; 
 
    background-color: #edeff0; 
 
} 
 
    
 
.progressbar li:after { 
 
    content: ''; 
 
    position: absolute; 
 
    width: 100%; 
 
    height: 4px; 
 
    background-color: #edeff0; 
 
    top: 4px; 
 
    left: -50%; 
 
    z-index: -1; 
 
} 
 
    
 
.progressbar li:first-child:after { 
 
    content: none; 
 
} 
 
    
 
.progressbar li.active { 
 
    color: green; 
 
} 
 
    
 
.progressbar li.active:before { 
 
    background-color: green; 
 
} 
 
    
 
.progressbar li.active + li:after { 
 
    background-color: green; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<!-- <div class="test"></div> --> 
 

 
<div class="container"> 
 
    <ul class="progressbar"> 
 
    \t <li class="active"><span>Step 1</span></li> 
 
    \t <li><span>Step 2</span></li> 
 
    \t <li><span>Step 3</span></li> 
 
    </ul> 
 
</div> 
 

 
<form id="form" action="procesar.php"> 
 
    <div id="step1" class="step"> 
 
    \t <h1>step 1</h1> 
 
    \t <a data-ref="#" onclick="show_step(2)">continue</a> 
 
    </div> 
 
    <div id="step2" class="step"> 
 
    \t <h1>step 2</h1> 
 
    \t <a data-ref="#" onclick="show_step(1)">after</a> 
 
    <a data-ref="#" onclick="show_step(3)">continue</a> 
 
    </div> 
 
    <div id="step3" class="step"> 
 
    \t <h1>step 3</h1> 
 
    \t <a data-ref="#" onclick="show_step(2)">after</a> 
 
    \t <button>Send</button> 
 
    </div> 
 
</form>

+1

Sadece animasyon yapmak için ne yaparsınız? –

+1

@BASEERHAIDERJAFRI Evet arkadaşım, ve eğer mümkünse bir sonraki adımı takip etmekten kaçınmak için olası formları nasıl doğrulayacağınıza dair bir örnek. Form doğrulama kullanımı için – gPH

+2

Jquery Validator (https://jqueryvalidation.org/documentation/) –

cevap

2

neye ihtiyacınız bu doğru bir anlayış var mı?

function animacion(caso) { 
 
    if (!caso) { 
 
     document.getElementsByClassName("progressbar")[0].setAttribute("data-active", ""); 
 
    } else { 
 
     document.getElementsByClassName("progressbar")[0].setAttribute("data-active", caso); 
 
    } 
 
    var items = document.getElementsByTagName("li"); 
 
    for (var i = 0; i < items.length; i++) { 
 
     var item = items[i]; 
 
     if (!caso) { 
 
      item.className = ""; 
 
     } else if (i < caso) { 
 
      item.className = "active"; 
 
     } else { 
 
      item.className = ""; 
 
     } 
 
    } 
 
} 
 

 
setTimeout(function() { 
 
    animacion(1); 
 
}, 1000); 
 
setTimeout(function() { 
 
    animacion(2); 
 
}, 2000); 
 
setTimeout(function() { 
 
    animacion(3); 
 
}, 3000); 
 
setTimeout(function() { 
 
    animacion(2); 
 
}, 4000); 
 
setTimeout(function() { 
 
    animacion(1); 
 
}, 5000); 
 
setTimeout(function() { 
 
    animacion(null); 
 
}, 6000);
.container { 
 
\t width: 100%; 
 
} 
 
.progressbar { 
 
\t counter-reset: step; 
 

 
} 
 
.progressbar li { 
 
\t list-style-type: none; 
 
\t float: left; 
 
\t width: 33.33%; 
 
\t position: relative; 
 
\t text-align: center; 
 
} 
 
.progressbar li > * { 
 
\t position: relative; 
 
\t padding-bottom: 20px; 
 
\t display: inline-block; 
 
\t font-size: 1.4rem; 
 
\t color: #2c3f4c; 
 
\t top: -45px; 
 
\t /* new code start */ 
 
\t top: -65px; 
 
\t /* new code end */ 
 
} 
 
.progressbar li:before { 
 
\t content: ''; 
 
\t width: 12px; 
 
\t height: 12px; 
 
\t display: block; 
 
\t text-align: center; 
 
\t margin: 0 auto; 
 
\t border-radius: 50%; 
 
\t background-color: #edeff0; 
 
} 
 
.progressbar li:after { 
 
\t content: ''; 
 
\t position: absolute; 
 
\t width: 100%; 
 
\t height: 4px; 
 
\t background-color: #edeff0; 
 
\t top: 4px; 
 
\t left: -50%; 
 
\t z-index: -1; 
 
} 
 
.progressbar li:first-child:after { 
 
\t content: none; 
 
} 
 
.progressbar li.active { 
 
\t color: green; 
 
} 
 
.progressbar li.active:before { 
 
\t background-color: green; 
 
\t /* new code start */ 
 
\t -webkit-transition: background 300ms ease; 
 
\t transition: background 300ms ease; 
 
\t -webkit-transition-delay: 300ms; 
 
\t transition-delay: 300ms; 
 
\t /* new code end */ 
 
} 
 

 
/* removed code start */ 
 
/* 
 
.progressbar li.active + li:after { 
 
\t background-color: green; 
 
} 
 
*/ 
 
/* removed code end */ 
 

 
/* new code start */ 
 
.progressbar { 
 
\t position: relative; 
 
\t padding: 0; 
 
\t margin: 0; 
 
} 
 
.progressbar:after { 
 
\t content: ""; 
 
\t height: 4px; 
 
\t left: 16.666%; 
 
\t background: green; 
 
\t top: 4px; 
 
\t position: absolute; 
 
\t -webkit-transition: width 300ms ease; 
 
\t transition: width 300ms ease; 
 
} 
 
.progressbar[data-active="1"]:after { 
 
\t width: 0; 
 
} 
 
.progressbar[data-active="2"]:after { 
 
\t width: 33%; 
 
} 
 
.progressbar[data-active="3"]:after { 
 
\t width: 66%; 
 
} 
 
.progressbar[data-active=""]:before { 
 
\t opacity: 0; 
 
} 
 
.progressbar:not([data-active=""]):before { 
 
\t opacity: 1; 
 
\t -webkit-transition: left 300ms ease, opacity 300ms ease; 
 
\t transition: left 300ms ease, opacity 300ms ease; 
 
} 
 
.progressbar[data-active="1"]:before { 
 
\t left: 16.666%; 
 
} 
 
.progressbar[data-active="2"]:before { 
 
\t left: 50%; 
 
} 
 
.progressbar[data-active="3"]:before { 
 
\t left: 83.333%; 
 
} 
 
.progressbar:before { 
 
\t content: ""; 
 
\t height: 16px; 
 
\t width: 16px; 
 
\t margin-top: -24px; 
 
\t margin-left: -8px; 
 
\t left: 16.666%; 
 
\t background: khaki; 
 
\t top: 4px; 
 
\t position: absolute; 
 
\t -webkit-transition: left 300ms ease; 
 
\t transition: left 300ms ease; 
 
} 
 
/* new code end */
<div class="container"> 
 
    <br><br><br><br><br><br> 
 
    <ul class="progressbar" data-active=""> 
 
     <li><span>Step 1</span></li> 
 
     <li><span>Step 2</span></li> 
 
     <li><span>Step 3</span></li> 
 
    </ul> 
 
</div>

biçimlendirme ve stil küçük değişiklik yoktur

. Rectange, simgelerinizi ekleyebileceğiniz bloğu gösterir.

+0

Bu harika, ancak yalnızca javascript'te ve sihirbaz jquery + ajax'ta. – gPH

+0

ajax'inize setStep işlevini koyun. .done gibi (işlev (e) {setStep (e)}) Çalışacağına inanıyorum. –

+0

bu şekilde https://jsfiddle.net/un2n17wj/ çok iyi çalışıyor ancak değişikliklerin görülebilmesi için sayfayı güncelleyin, sizden bahseden link gibi kontrolleri eklemeniz konusunda bir fikriniz var. – gPH