• js实现广告条+缓冲效果/键盘事件实现小人跑步


    1. <style>
    2. .box {
    3. margin: 0 auto;
    4. width: 1000px;
    5. height: 5000px;
    6. box-shadow: 0 0 0 1px #000;
    7. background-color: aquamarine;
    8. }
    9. .bon {
    10. width: 10000px;
    11. height: 2000px;
    12. margin: 0 auto;
    13. box-shadow: 0 0 0 1px #000;
    14. background-color: bisque;
    15. }
    16. .foot {
    17. width: 1000px;
    18. height: 2000px;
    19. margin: 0 auto;
    20. box-shadow: 0 0 0 1px #000;
    21. background-color: darkcyan;
    22. }
    23. .abs {
    24. position: absolute;
    25. top: 400px;
    26. transition: .4s;
    27. }
    28. a {
    29. position: absolute;
    30. top: 0;
    31. right: 0;
    32. }
    33. style>
    34. head>
    35. <body>
    36. <div class="box">div>
    37. <div class="bon">div>
    38. <div class="foot">div>
    39. <div class="abs">
    40. <img src="./img/pic.jpg" alt="" class="img">
    41. <a href="javascript:;" id="x">xa>
    42. div>
    43. body>
    44. <script>
    45. var odiv = document.querySelector(".abs");
    46. var btn = document.getElementById("x");
    47. window.onscroll = function () {
    48. var top = document.documentElement.scrollTop; //获取当前滚动条位置
    49. var left = document.documentElement.scrollLeft;
    50. odiv.style.top = top + 400 + "px";
    51. odiv.style.left = left + "px"
    52. }
    53. btn.onclick = function () {
    54. odiv.style.display = "none";
    55. setTimeout(() => {
    56. odiv.style.display = "block";
    57. }, 1000);
    58. }
    59. script>

    图片素材icon-default.png?t=M7J4http://链接:https://pan.baidu.com/s/1lmEjwFnZB86UKGCYSxl4GQ?pwd=izbh 提取码:izbh

    1. <style>
    2. .box img {
    3. position: absolute;
    4. top: 0;
    5. left: 0;
    6. }
    7. style>
    8. head>
    9. <body>
    10. <div class="box">
    11. <img src="./img/lu-0.png" alt="">
    12. div>
    13. body>
    14. <script>
    15. var odiv = document.querySelector(".box");
    16. var oimg = document.querySelector(".box img");
    17. var num = -1;
    18. document.addEventListener("keydown", function (ev) {
    19. // console.log(ev.keyCode);
    20. switch (ev.keyCode) {
    21. case 40: //下
    22. case 83:
    23. num++;
    24. oimg.src = "./img/down-" + num + ".png";
    25. if (num === 4) {
    26. num = 1;
    27. }
    28. oimg.style.top = oimg.offsetTop + 10 + "px";
    29. break;
    30. case 39: //右
    31. case 68:
    32. num++;
    33. oimg.src = "./img/right-" + num + ".png";
    34. if (num === 4) {
    35. num = 1;
    36. }
    37. oimg.style.left = parseInt(getComputedStyle(oimg).left) + 10 + "px";
    38. break;
    39. case 38: //上
    40. case 87:
    41. num++;
    42. oimg.src = "./img/up-" + num + ".png";
    43. if (num === 4) {
    44. num = 1;
    45. }
    46. oimg.style.top = parseInt(getComputedStyle(oimg).top) - 10 + "px";
    47. break;
    48. case 37: //左
    49. case 65:
    50. num++;
    51. oimg.src = "./img/left-" + num + ".png";
    52. if (num === 4) {
    53. num = 1;
    54. }
    55. oimg.style.left = parseInt(getComputedStyle(oimg).left) - 10 + "px";
    56. break;
    57. }
    58. })
    59. script>

    源码2

    1. <style>
    2. #pic {
    3. position: absolute;
    4. left: 300px;
    5. top: 300px;
    6. }
    7. style>
    8. head>
    9. <body>
    10. <img src="./img/down-0.png" alt="" id="pic">
    11. body>
    12. <script>
    13. var oImg = document.getElementById("pic");
    14. var i = -1;
    15. document.addEventListener("keydown", function (ev) {
    16. console.log(ev.keyCode);
    17. switch (ev.keyCode) {
    18. case 37:
    19. case 65:
    20. oImg.style.left = oImg.offsetLeft - 10 + "px";
    21. changeImg("left");
    22. break;
    23. case 38:
    24. case 87:
    25. oImg.style.top = oImg.offsetTop - 10 + "px";
    26. changeImg("up");
    27. break;
    28. case 39:
    29. case 68:
    30. oImg.style.left = oImg.offsetLeft + 10 + "px";
    31. changeImg("right");
    32. break;
    33. case 40:
    34. case 83:
    35. oImg.style.top = oImg.offsetTop + 10 + "px";
    36. changeImg("down");
    37. break;
    38. }
    39. })
    40. function changeImg(dir) {
    41. i++;
    42. if (i >= 5) {
    43. i = 0;
    44. }
    45. oImg.src = "./img/" + dir + "-" + i + '.png';
    46. }
    47. script>

    鼠标拖动小滑块案例

    1. <style>
    2. #box {
    3. position: absolute;
    4. width: 200px;
    5. height: 200px;
    6. background-color: #f00;
    7. }
    8. style>
    9. head>
    10. <body>
    11. <div id="box">div>
    12. body>
    13. <script>
    14. var oDiv = document.getElementById("box");
    15. oDiv.onmousedown = function (ev) {
    16. // console.log(ev.clientX);
    17. var rectX = ev.clientX - oDiv.offsetLeft;
    18. var rectY = ev.clientY - oDiv.offsetTop;
    19. document.onmousemove = function (ev) {
    20. var left = ev.clientX - rectX;
    21. var top = ev.clientY - rectY;
    22. oDiv.style.left = left + 'px';
    23. oDiv.style.top = top + 'px';
    24. }
    25. oDiv.onmouseup = function () {
    26. document.onmousemove = null;
    27. };
    28. }
    29. script>

  • 相关阅读:
    (计算机组成原理)第三章存储系统-第四节2:固态硬盘SSD
    React技术栈支援Vue项目,你需要提前了解的
    EN 16069建筑物用隔热产品.工厂制造的聚乙烯泡沫(PEF)产品—CE认证
    WorldCoin 运营数据,业务安全分析
    Python三目运算符(三元运算符)用法详解(含Python代码)
    Python 使用openpyxl处理Excel文件
    3. 投票 案例项目(合集)
    SpringCloud 微服务接口限流的两种方式
    江淮500后桥壳体机械加工工艺及精镗两侧面孔工序夹具设计
    NPM 常用命令(五)
  • 原文地址:https://blog.csdn.net/m0_59642141/article/details/126431103