- Thi
- Automatically reload page if js file changes
- Add MathJax to website
- Heading hover anchor links
- Back to top button
- Hide / Show box
- Click to enlarge photo
- Prevent default event
- Search + result + navigation
- Scrolling headings in TOC
- Fetch starred repository (JSON to
ol)
Thi
Ref: π Site: update briefs π Note: magnific popup π Note: jekyll inner links π Note: secret recipes
Automatically reload page if js file changes
- Install nodejs.
- Install live-server using nodejs:
npm install -g live-server. cdto the project folder.- run
live-server(accept all networks notification) - Browse: http://127.0.0.1:8080
- Enjoy!
::: warning It may not reload the browser (it only detects the changes)! :::
Add MathJax to website
π Check the codes.
Anchor links hidden by fixed navigation
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!
Heading hover anchor links
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
atag 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
| Title | Type | Excerpt |
|---|---|---|
| learningjavascript canvas tag | post | Friday, getting started with the book by coding for user input canvas, amazing! |
| jsimpatient learning path | post | javascript revisited |
{# nothing on index to avoid visible raw text #}