Last active
February 8, 2020 08:24
-
-
Save fixedis/6abe98767d925c2de991d58191467a94 to your computer and use it in GitHub Desktop.
Функция позволяет создавать пошаговый опросник (проще не куда) | Описание возможностей в комментариях
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Step (step, step_line, step_wrap, step_but, step_function_check, step_function_done, step_function_end) { | |
var Sl = { | |
stepCheck: null, | |
stepline: null, | |
stepLength: null, | |
stepNow: null, | |
stepBut: null, | |
stepFunctionCheck: null, | |
Set: function(step, step_line, step_wrap, step_but, step_function_check, step_function_done, step_function_end) { | |
Sl.stepCheck = $(step+' span'); | |
Sl.stepline = $(step_line+' div'); | |
Sl.stepWrap = $(step_wrap); | |
Sl.stepLength = $(step_wrap).children('li').length; | |
Sl.stepNow = 1; | |
Sl.stepBut = $(step_but); | |
Sl.stepFunctionCheck = step_function_check; | |
Sl.stepFunctionEnd = step_function_end; | |
console.log(Sl.stepNow, Sl.stepLength); | |
return Sl; | |
}, | |
StepAnim: function() { | |
Sl.stepline.eq(0).css({ | |
'width': 'calc(100% / '+Sl.stepLength+' * '+Sl.stepNow, | |
'transition': '1.0s'}); | |
Sl.stepWrap.children().fadeOut(0); | |
$(Sl.stepWrap.children()[Sl.stepNow - 1]).fadeIn(0); | |
}, | |
StepNext: function() { | |
Sl.stepNow++; | |
Sl.stepCheck.eq(0).html(Sl.stepNow); | |
Sl.StepAnim(); | |
return Sl; | |
}, | |
StepCancel: function() { | |
alert('Отменено'); | |
return Sl; | |
}, | |
Click: function() { | |
Sl.stepCheck.eq(0).html(Sl.stepNow); | |
Sl.stepCheck.eq(1).html(Sl.stepLength); | |
Sl.StepAnim(); | |
Sl.stepBut.click(function(event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
(Sl.stepFunctionCheck(Sl.stepNow)) ? | |
(Sl.stepLength == Sl.stepNow) ? | |
Sl.stepFunctionEnd() | |
: Sl.StepNext() | |
: Sl.StepCancel(); | |
}); | |
return 'Выполнено без ошибок!'; | |
} | |
}; | |
console.log(Sl.Set(step, step_line, step_wrap, step_but, step_function_check, step_function_done, step_function_end).Click()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Функция позволяет создавать пошаговый опросник.
Это минимум необходимый для просмотра результата.
CSS
Интересный момент заключается в том что блоки (step_test, step_line_test, step_wrap_test, step_but_test) могут быть размещены где угодно, в любом месте вашего HTML/PHP документа. Включая разнобой.
HTML
Суть заключается в том что при каждом шаге выполняется код в switch где номер шага равен текущему case где вы можете осуществлять все необходимые проверки в случае успеха возвращаем true и идет переключение на следующий шаг в противном случае возращаем false и выполняется функция error. В случае когда все шаги пройдены выполняется функция last_step.
JS