3-4 折翼天使表现特性二:位置跟随
本节编程练习不计算学习进度,请电脑登录imooc.com操作

折翼天使表现特性二:位置跟随

折翼天使表现特性二:位置跟随

任务

老师视频里的不同布局写法,不是习题!!不是习题!!!

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>折翼天使表现特性二:位置跟随</title>
  6. <style>
  7. input[type=button] {
  8. height: 32px;
  9. font-size: 100%;
  10. }
  11. p { margin-left: 260px; }
  12. img + p { margin-top: 60px; }
  13. </style>
  14. </head>
  15.  
  16. <body>
  17. <img src="http://img1.sycdn.imooc.com//54447b06000171a002560191.jpg">
  18. <div><img src="http://img1.sycdn.imooc.com//54447f4a0001eb7d01910256.jpg"></div>
  19. <img src="http://img1.sycdn.imooc.com//54447f550001ccb002560191.jpg">
  20. <p><input type="button" id="block" value="点击第2张图片应用display:block"></p>
  21. <p><input type="button" id="button" value="点击第2张图片应用position:absolute变天使"></p>
  22. <script>
  23. var block = document.getElementById("block"),
  24. button = document.getElementById("button"),
  25. image2 = document.getElementsByTagName("img")[1];
  26. if (block && button && image2) {
  27. var value_init_button = button.value;
  28. button.onclick = function() {
  29. if (this.value == value_init_button) {
  30. image2.style.position = "absolute";
  31. this.value = "撤销";
  32. } else {
  33. image2.style.position = "";
  34. this.value = value_init_button;
  35. }
  36. };
  37.  
  38. var value_init_block = block.value;
  39. block.onclick = function() {
  40. if (this.value == value_init_block) {
  41. image2.style.display = "block";
  42. this.value = "撤销";
  43. } else {
  44. image2.style.display = "";
  45. this.value = value_init_block;
  46. }
  47. };
  48. }
  49. </script>
  50. </body>
  51. </html>
下一节