فرم چندمرحلهای (Wizard Form) با انیمیشن
فرمهای چندمرحلهای (Wizard Forms) تجربه کاربری رو بهبود میبخشن و کاربر رو خسته نمیکنن. در این مقاله یک سورس کد فرم چندمرحلهای با انیمیشن انتقال براتون آماده کردیم.
ویژگیها
- ۳ مرحله: اطلاعات شخصی، اطلاعات تماس، تأیید نهایی
- نوار پیشرفت با انیمیشن
- اعتبارسنجی فیلدها در هر مرحله
- انتقال روان بین مراحل
- طراحی مدرن و ریسپانسیو
کد HTML
<div class="wizard-container">
<div class="progress-bar">
<div class="progress" id="progress"></div>
<div class="step-indicators">
<div class="step active" data-step="1">۱</div>
<div class="step" data-step="2">۲</div>
<div class="step" data-step="3">۳</div>
</div>
</div>
<div class="wizard-form">
<div class="form-step active" id="step1">
<h3>اطلاعات شخصی</h3>
<input type="text" placeholder="نام و نام خانوادگی" required>
<input type="email" placeholder="ایمیل" required>
</div>
<div class="form-step" id="step2">
<h3>اطلاعات تماس</h3>
<input type="tel" placeholder="شماره تماس" required>
<textarea placeholder="آدرس"></textarea>
</div>
<div class="form-step" id="step3">
<h3>تأیید نهایی</h3>
<p>اطلاعات شما ثبت شد. روی ارسال کلیک کنید.</p>
</div>
</div>
<div class="wizard-buttons">
<button class="btn-prev" onclick="prevStep()">مرحله قبل</button>
<button class="btn-next" onclick="nextStep()">مرحله بعد</button>
</div>
</div>
کد CSS
.wizard-container {
max-width: 500px;
margin: 40px auto;
padding: 30px;
background: white;
border-radius: 20px;
box-shadow: 0 10px 40px rgba(0,0,0,0.1);
font-family: 'IRANSans', Tahoma, sans-serif;
direction: rtl;
}
.progress-bar {
position: relative;
height: 4px;
background: #e0e0e0;
border-radius: 2px;
margin-bottom: 30px;
}
.progress {
height: 100%;
background: linear-gradient(90deg, #6c5ce7, #a29bfe);
border-radius: 2px;
transition: width 0.5s ease;
width: 33.33%;
}
.step-indicators {
display: flex;
justify-content: space-between;
position: relative;
top: -12px;
}
.step {
width: 28px;
height: 28px;
border-radius: 50%;
background: #e0e0e0;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-weight: bold;
transition: all 0.3s;
}
.step.active {
background: #6c5ce7;
color: white;
transform: scale(1.2);
}
.form-step {
display: none;
animation: slideIn 0.4s ease;
}
.form-step.active {
display: block;
}
.form-step input, .form-step textarea {
width: 100%;
padding: 12px 15px;
margin: 10px 0;
border: 2px solid #e0e0e0;
border-radius: 10px;
font-size: 14px;
transition: border-color 0.3s;
box-sizing: border-box;
}
.form-step input:focus {
border-color: #6c5ce7;
outline: none;
}
.wizard-buttons {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
.btn-prev, .btn-next {
padding: 10px 25px;
border: none;
border-radius: 10px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s;
}
.btn-next {
background: #6c5ce7;
color: white;
}
.btn-next:hover {
background: #5a4bd1;
transform: translateY(-2px);
}
.btn-prev {
background: #f0f0f0;
color: #666;
}
@keyframes slideIn {
from { opacity: 0; transform: translateX(30px); }
to { opacity: 1; transform: translateX(0); }
}
کد جاوا اسکریپت
let currentStep = 1;
const totalSteps = 3;
function nextStep() {
if (currentStep < totalSteps) {
document.getElementById(`step${currentStep}`).classList.remove('active');
currentStep++;
document.getElementById(`step${currentStep}`).classList.add('active');
updateProgress();
} else {
alert('فرم با موفقیت ارسال شد!');
}
}
function prevStep() {
if (currentStep > 1) {
document.getElementById(`step${currentStep}`).classList.remove('active');
currentStep--;
document.getElementById(`step${currentStep}`).classList.add('active');
updateProgress();
}
}
function updateProgress() {
const progress = document.getElementById('progress');
progress.style.width = `${(currentStep / totalSteps) * 100}%`;
document.querySelectorAll('.step').forEach((step, index) => {
step.classList.toggle('active', index < currentStep);
});
}
جمعبندی
این فرم چندمرحلهای رو میتونید در فرمهای ثبتنام، سفارش و تماس با ما استفاده کنید. برای سورس کدهای بیشتر به بخش سورس کد طاووس وب سر بزنید.