{"id":1937,"date":"2023-03-25T14:26:38","date_gmt":"2023-03-25T06:26:38","guid":{"rendered":""},"modified":"2023-03-25T14:26:38","modified_gmt":"2023-03-25T06:26:38","slug":"ES6 \u52a8\u753b","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1937.html","title":{"rendered":"ES6 \u52a8\u753b"},"content":{"rendered":"
\n
\u4f7f\u7528 setInterval() \u65b9\u6cd5: \u5b83\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff0c\u4e00\u4e2a\u51fd\u6570\u548c\u4e00\u4e2a\u6574\u6570\u3002\u6b64\u65b9\u6cd5\u4f7f\u7528 clearInterval() \u65b9\u6cd5\u7ec8\u6b62\u3002<\/span> <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/body>
\n \u4f7f\u7528 requestAnimationFrame() \u65b9\u6cd5: \u5f53\u5c4f\u5e55\u51c6\u5907\u597d\u63a5\u53d7\u4e0b\u4e00\u6b21\u91cd\u7ed8\u65f6\uff0c\u6b64\u65b9\u6cd5\u8fd0\u884c\u8be5\u51fd\u6570\u3002\u5b83\u9700\u8981\u4e00\u4e2a\u53c2\u6570\u51fd\u6570\u3002\u5f53\u6211\u4eec\u9012\u5f52\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5\u65f6\uff0c\u52a8\u753b\u6548\u679c\u5c31\u4f1a\u53d1\u751f\u3002\u9884\u671f\u7684\u52a8\u753b\u662f\u9010\u5e27\u521b\u5efa\u7684\uff0c\u5e76\u4e14\u5728\u6d4f\u89c8\u5668\u51c6\u5907\u597d\u65f6\u8c03\u7528\u6bcf\u4e00\u5e27\u3002<\/span> <\/p>\nsetInterval() \u65b9\u6cd5<\/h2>\n
anime = setInterval(show, t);\n\/\/It calls the function show after every t milliseconds<\/span>\nclearInterval(anime);\n\/\/It terminates above process<\/span><\/pre>\n
requestAnimationFrame() \u65b9\u6cd5<\/h2>\n
<html> \n <head> \n <script type = \"text\/javascript\"<\/span>> \n \n var <\/span>img = null<\/span>; \n function init(){ \n img = document.getElementById<\/span>('myimg'<\/span>);\n img.style.position = 'relative'<\/span>; \n img.style.left = '50px'<\/span>; \n } \n function moveRight(){ \n img.style.left = parseInt<\/span>(\n img.style.left) + 100 + 'px'<\/span>; \n } \n window.onload = init; \n \n <\/script> \n <\/head> \n \n <body> \n <form> \n <img id = \"myimg\"<\/span> src = \"train1.png\"<\/span> \/> \n <center>\n <p>Click the below button to move the image right<\/p> \n <input type = \"button\"<\/span> value = \"Click Me\"<\/span> onclick = \"moveRight();\"<\/span> \/>\n <\/center> \n <\/form>\n <\/body>\n \n<\/html><\/pre>\n
<html> \n <head> \n <title>JavaScript Animation<\/title> \n <script type = \"text\/javascript\"<\/span>> \n var <\/span>anime ; \n function init(){ \n img = document.getElementById<\/span>('myimg'<\/span>); \n img.style.position = 'relative'<\/span>; \n img.style.left = '0px'<\/span><\/span>; \n } \n function towardRight(){ \n img.style.left = parseInt<\/span>(img.style.left) + 10 + 'px'<\/span>; \n anime = setTimeout(towardRight,50); \n } \n function stop() { \n clearTimeout(anime); \n img.style.left = '0px'; \n } \n window.onload = init; \n <\/script> \n <\/head> \n <body> \n <form> \n <img id = \"myimg\"<\/span> src = \"train1.png\"<\/span> \/> \n <center>\n <h2 style=\"color:darkblue;\"<\/span>>Click the following buttons to handle animation<\/h2> \n <input type=\"button\"<\/span><\/span> value=\"Start\"<\/span> onclick = \"towardRight();\"<\/span> \/> \n <input type = \"button\" value=\"Stop\"<\/span> onclick = \"stop();\"<\/span> \/> \n <center>\n <\/form> \n <\/body> \n<\/html><\/pre>\n
\u9f20\u6807\u4e8b\u4ef6\u7684\u56fe\u50cf\u7ffb\u8f6c<\/h2>\n
<html>\n \n <head>\n \n <script type = \"text\/javascript\"<\/span>>\n if(document.images) {\n var <\/span>img1 = new <\/span>Image(); \n img1.src = \"cat.jpg\"<\/span><\/span>;\n var <\/span>img2 = new <\/span>Image(); \n img2.src = \"tiger.jpg\"<\/span>;\n }\n <\/script>\n <\/head>\n \n <body>\n <center>\n \n <a href = \"#\"<\/span> onMouseOver = \"document.myImg.src = img2.src;\"<\/span><\/span>\n onMouseOut = \"document.myImg.src = img1.src;\"<\/span>>\n <img name = \"myImg\"<\/span> src = \"cat.jpg\" \/>\n <\/a><br><br><br>\n <h1>Move your mouse over the image to see the result<\/h1>\n <\/center>\n <\/body>\n<\/html><\/pre>\n
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"ES6 \u52a8\u753bzh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[161],"tags":[],"class_list":["post-1937","post","type-post","status-publish","format-standard","hentry","category-es6jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1937"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1937"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1937\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}