지금까지 5 시간 쯤 웹을 둘러 보았습니다. 내 문제에 대한 해결책을 찾을 수 없습니다. 모든 플러그인에 타이핑 효과를주는 플러그인을 작성했습니다. 주어진 요소와 그것을 완벽하게 하나의 요소에 사용하는 경우에만 작동하지만, 내가 두 번째 요소에 그것을 사용하려면, 그것은 두 번째 하나를 수행하고 여기 왜 : 내 플러그인에 나는 "setInterval"을 사용 특정 속도로 타이핑하고 특정 문자를 지연시키기 위해 글자를 검사하면, 플러그인을 두 번 이상 호출하여 변수에 새 값을 설정하고 간격을 새로 설정된 값과 충돌시키고 모든 것을 망칠 때 문제가 발생합니다 쪽으로. 여기여러 요소에 jQuery 플러그인을 할당합니다.
(function ($) {
//typing effect for text
$.fn.typingText = function (options) {
var setting = $.extend({
//the starting point ==> *(it starts typing when the scrollbar hit the starting point)
start: 0,
//the user given delay character ==> *(it delays the typing when it hits this character) ==> *(must be a character not a digit or alphabet)
delayChar: '.',
//the speed of typer ==> *(must be at least 50)
speed: 100,
//the delay duration when it hits delaying characters ==> *(delaying characters are ? ! . and any other given character in delayChar variable)
delay: 500
}, options);
if (setting.speed < 50) {
setting.speed = 50;
}
if (setting.delay < 100) {
setting.delay = 100;
}
setting.delayChar = setting.delayChar.slice(0, 1);
window.that = $(this);
if ($(document).scrollTop() >= setting.start) {
$(this).css('display', 'block');
window.text = $(this).text();
window.textLength = window.text.length;
window.char = 0;
setting.delayChar = '^\\' + setting.delayChar;
$(this).text('');
$(this).html('<span class="textLine"></span>');
$(this).append('<span class="blinkingLine">|</span>');
window.blinking = setInterval(function() {
$('.blinkingLine').animate({
opacity: 0
}, 300);
setTimeout(function() {
$('.blinkingLine').animate({
opacity: 1
}, 300);
}, 300);
}, 600);
function type() {
window.that.children('.textLine').text(window.text.substr(0, window.char));
window.lastChar = window.that.children('.textLine').text().slice(window.that.children('.textLine').text().length - 1);
window.char++;
if (window.char > window.textLength) {
window.that.children('.textLine').text(window.that.children('.textLine').text().substr(0, window.textLength));
$('.blinkingLine').remove();
clearInterval(window.startTyping);
clearInterval(window.blinking);
clearInterval(window.checking);
}
}
window.timer = 0;
window.startTyping = setInterval(type, setting.speed);
window.checking = setInterval(function() {
if (!window.delaying || typeof window.delaying == 'undefined' || window.timer >= setting.delay) {
if (window.lastChar.match('^\\?') || window.lastChar.match('^\\.') || window.lastChar.match('^\\!') || window.lastChar.match(setting.delayChar)) {
if (window.timer >= setting.delay) {
window.timer = 0;
window.char++;
type();
window.startTyping = setInterval(type, setting.speed);
window.delaying = false;
} else {
window.delaying = true;
clearInterval(window.startTyping);
window.startTyping = null;
}
}
} else {
window.timer = window.timer + 50;
}
}, 50);
}
};
})(jQuery);
$(function() {
$('#title').typingText();
$('#title2').typingText();
});
코드 문제를 볼 수있는 jsFiddle입니다 : 여기
는 코드입니다.플러그인 작성에 대한 내 접근 방식으로 뭔가를해야한다는 것을 알고 있지만, 객체 지향 플러그인 작성과 같은 웹에서 몇 가지 제안을 시도했지만 여전히 해결책을 찾지 못했습니다! 어떤 도움이나 제안을 주시면 감사하겠습니다.
()'. – Barmar
좀 더 수수께끼주세요. 나는 그것을 .data()에 붙이려고했지만 행운이 없다. 어쩌면 나는 그것을 어떻게하는지 모른다. : -s –
@Barmar는 .data() 또는 기타 변수에 변수를 첨부 할 필요가 없으며 완벽하게 작동하는 자체 답변을 확인하십시오. –