Web tips

HTML

No selection

oncontextmenu="return false;" onselectstart="return false"

add this in tag, broswer will not allow user to select this element. It’s helpful to set a button, because sometimes user will select the text on the button, and it will affect experience.

Javascript

Circle index in Array

When design a photo album, developer usually collect all src (link) of image in a Array, and control index to choose a link then exhibit on HTML.

When user click button, the index will increase or decrease, and the img tag will update src. But the array has a fixed length, if index bigger / less than length / 0, it will be a problem.

So I found this code:

while (index < 0) index += srcArr.length
while (index > srcArr.length) index -= srcArr.length

It means, if the index become negative, it will become the last element in array, as well as other situation (first). So index will circle change.


For LCC MA.IVM Reflective Journal
/ Home / Archives / Heyao.art

Made by Heyao / Site by HEXO