To write a JS effect step:
- First realize the layout;
- Understand the principle of animation implementation;
- Understand the JS syntax;
JS how to get elements?
document.getElementById(‘link’)
Event
onclick
onmouseover
onmouseout
onmousemove //鼠标的抚摸事件
onmousedown
onmouseup
- keyboard events;
- System events:
onload //加载完了html代码后再执行script脚本
- form events;
- Custom events: Native No, we have to do it ourselves.
How do I add an event?
Just like Jiangzi:元素.onmouseover
Function
That's the order, do something.
function abc(){……//不会主动执行}
- Call directly:
abc();
- Event Invocation:
元素.onmouseover=abc;//千万不要加括号
- Anonymous invocation:
元素.onmouseover=function(){};
Test
Beginners should keep writing at any time to test the habit.
alert(1);//带一个确定按钮的警告框alert(‘okhahaha’);
document.getElementById(‘link’)Too long? Use variables!
var hahaha=document.getElementById(‘link’);
Want to move an element out of your sight?
display:none;//消失了,不占地儿
visibility:hidden;//只是隐藏了,还是占地儿
- Change the width and height: With JS can achieve growth animation effect;
- Change the transparency: with JS can achieve fade animation effect;
- Change the absolute positioning;
- Take a white div to cover it: it can even achieve the effect of water droplet retraction;
- margin negative;
JavaScript Basic Learning Experience 02