Tue, Oct 26, 21, reload page, lose focus, add MathJax to website, hover anchor links, default event, search result navigation, starred repo json
This is a draft, the content is not complete and of poor quality!

Thi

Ref: πŸ‘‰ Site: update briefs πŸ‘‰ Note: magnific popup πŸ‘‰ Note: jekyll inner links πŸ‘‰ Note: secret recipes

Automatically reload page if js file changes

  1. Install nodejs.
  2. Install live-server using nodejs: npm install -g live-server.
  3. cd to the project folder.
  4. run live-server (accept all networks notification)
  5. Browse: http://127.0.0.1:8080
  6. Enjoy!

::: warning It may not reload the browser (it only detects the changes)! :::

Add MathJax to website

πŸ‘‰ Check the codes.

If you use table of content for posts in which links starting with # link to headings. After jumping, headings are usually hidden by the fixed navigation. Adding below script before </body> tag can solve the problem (change value 100 to change where the page jump).link

πŸ‘‰ Check the codes. Update 10/26/21: This method is not good. It works only if we click on an <a> tag which starts with # in the href. In the case of which inside <a> containing an <svg>, for example, it won’t work!

πŸ‘‰ Check the codes.link

Back to top button

Click and go back to the top of the page using javascript with smooth effect.

πŸ‘‰ Check the codes.

Hide / Show box

Auto hide / show the next div of the currently clicked div.

πŸ‘‰ Check the codes.

Advantage: We don’t need the id of content div, this method requires that div.hs__content comes right after div.hs__title, otherwise it won’t work!

Click to enlarge photo

If some photos on your page are too small and you wanna add a function in that users can click on the photo to enlarge it. This technique requires Bootstrap 4.

πŸ‘‰ Check the codes.

Prevent default event

Stop arrow key acts as usual,

window.addEventListener("keydown", function(e) {
	// space and arrow keys
	if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
		e.preventDefault();
	}
}, false);

If div_1 inside div_2, prevent actions in div_2 when performs on div_1 (check this example), use e.stopPropagation().

Search + result + navigation

  • Auto close the result if losing focus.
  • Cycling the result items with arrow up/down keys.
  • Auto focus to the a tag of the title.

πŸ‘‰ Check the codes.

Scrolling headings in TOC

Follow the position of viewport, auto highlight heading in toc w.r.t the current heading on page

πŸ‘‰ Check the codes.

Fetch starred repository (JSON to ol)

Automatically fetch a list of Github starred repositories using Github API and display it under <ol> html tag.link

πŸ‘‰ Check the codes.

The following wiki, pages and posts are tagged with

TitleTypeExcerpt
learningjavascript canvas tag post Friday, getting started with the book by coding for user input canvas, amazing!
ES6 tools techniques and paradigm post Fri, Oct 15, 21, a practical and thorough coverage of important language concepts.
Javascript 101 post Tue, Oct 19, 21, quick reference for fundamental things in javascript
Javascript tips at par with this jekyll post Tue, Oct 26, 21, reload page, lose focus, add MathJax to website, hover anchor links, default event, search result navigation, starred repo json
Javascript dome pattern post Thu, Oct 28, 21, Javascipt Patterns μ±…μ˜ 8μž₯ 'DOM κ³Ό λΈŒλΌμš°μ € νŒ¨ν„΄' 을 μš”μ•½
D3 square.github.io data binding post Thu, Nov 11, 21, data binding
D3.js square.github.io tutorial post Thu, Nov 11, 21, data binding
μžλ°”μŠ€ν¬λ¦½νŠΈλŠ” μ™œ κ·Έ λͺ¨μ–‘μΌκΉŒ? page λ”κΈ€λΌμŠ€ ν¬λ½ν¬λ“œκ°€ μ•Œλ €μ£ΌλŠ”
javascript for impatient page Exploit the power of modern javascript and avoid the pitfalls
λ¦¬νŒ©ν† λ§ 2판 page μ½”λ“œ ꡬ쑰λ₯Ό μ²΄κ³„μ μœΌλ‘œ κ°œμ„ ν•˜μ—¬ 효율적인 λ¦¬νŒ©ν„°λ§ κ΅¬ν˜„ν•˜κΈ°
μžλ°”μŠ€ν¬λ¦½νŠΈ μ½”λ”©μ˜ 기술 page λ˜‘λ˜‘ν•˜κ²Œ μ½”λ”©ν•˜λŠ” 법
jsimpatient learning path post javascript revisited