블로그 이미지
잡다한 취미 생활 및 일상에 대한 소소한 이야기를 적어나가는 블로그입니다.
붉은kkk

공지사항

최근에 올라온 글

최근에 달린 댓글

글 보관함

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

자바스크립트로 글이 써지는 듯한 효과를 나타내고 싶을 때 쓰면 좋은 라이브러리가 있습니다.

바로 'Typed.js' 인데요.

 

사용방법은 어렵지 않습니다.

 

https://mattboldt.com/demos/typed-js/

 

JavaScript Animated Typing with Typed.js | by Matt Boldt

Another demo made with love by Matt Boldt. Installation # With NPM npm install typed.js # With Yarn yarn add typed.js # With Bower bower install typed.js Setup var typed = new Typed('.element', { strings: ["First sentence.", "Second sentence."], typeSpeed:

mattboldt.com

CDN
<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11"></script>

예제 소스

<html>

<body>
    <div class="element"></div>
</body>

<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11"></script>
<script>
var options = {
  strings: ['<i>First</i> sentence.', '&amp; a second sentence.'],
  typeSpeed: 40
};

var typed = new Typed('.element', options);

</script>

</html>

이렇게 하면, strings에 있는 글자가 하나씩 타이핑 되는 효과를 볼 수 있습니다.

Upgrade된 예제 코드는 아래와 같아요

(커서 효과가 추가 되었습니다.)

<div> --> <span> 으로 변경된 것도 참조하세요.

커서 효과를 주려고 하니까 div는 제대로 되지 않고 span으로 해야 되더라구요^^;

<html>
<head>
    <meta charset="utf-8">
</head>

<body>
    <span class="element"></span>
</body>

<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11"></script>
<script>
var options = {
  strings: ['First sentence.', '&amp; a second sentence.', '테스트결과 만족 스러워요'],
  typeSpeed: 40,
  backSpeed: 100,
  fadeOut: false,
  smartBackspace: true,
  cursorChar: '_',
  loop: true
};

var typed = new Typed('.element', options);

</script>

</html>

 

마지막으로, 개발자의 요청사항을 만족시켜 줍시다.

'Typed.js' 사용 시 개발자에게 감사의 마음을 담아 사용함을 알려 주면 된다고 합니다.


Thanks for checking this out. If you have any questions, I'll be on Twitter.

If you're using this, let me know! I'd love to see it.

It would also be great if you mentioned me or my website somewhere. www.mattboldt.com