分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.youkuaiyun.com/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
需要两张图片,下载:http://download.youkuaiyun.com/detail/cometwo/9530731
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <title>放大镜练习</title> <style type="text/css"> * { margin: 0px; padding: 0px; } #small { width: 400px; height: 400px; overflow: hidden; margin-left: 10px; margin-top: 10px; z-index: 1; position: relative; border: 1px solid red; } #small img { position: absolute; top: 0; left: 0; } #float { display: block; width: 50px; height: 50px; background: green; opacity: 0.3; z-index: 2; position: absolute; display: none; } #big { width: 400px; height: 400px; overflow: hidden; margin-top: -400px; margin-left: 420px; position: relative; display: none; border: 1px solid blue; } #big img { position: absolute; left: 0; } p{ margin-top: 10px; margin-left: 10px; } </style> <script type="text/javascript"> window.onload = function() { window.onmousemove = function(e) { document.getElementById('cl').innerHTML = "鼠标指针pageX,pageY坐标:" + e.pageX + "," + e.pageY; } } </script> </head> <body> <div id="small"> <span id="float"></span> <img src="2.jpg"> </div> <div id="big"> <img id="no" src="1.jpg"> </div> <p><span id="cl"></span></p> <p><span id="zb"></span></p> <script type="text/javascript"> (function() { var oSmall = document.getElementById('small'); var oFloat = document.getElementById('float'); var oBig = document.getElementById('big'); var oImg = oBig.getElementsByTagName('img')[0]; oSmall.onmouseover = function() { oBig.style.display = 'block'; oFloat.style.display = 'block'; } oSmall.onmouseout = function() { oBig.style.display = 'none'; oFloat.style.display = 'none'; } oSmall.onmousemove = function(ev) { var oEvent = ev || event; /*****************/ var zb = document.getElementById('zb'); zb.innerHTML = "鼠标指针clientX,clientY的坐标:" + oEvent.clientX + "," + oEvent.clientY; zb.innerHTML = zb.innerHTML + ",</br>oSmall的offsetLeft,offsetTop:" + oSmall.offsetLeft + "," + oSmall.offsetTop; zb.innerHTML = zb.innerHTML + ",</br>oFloat的offsetWidth,offsetHeight:" + oFloat.offsetWidth + "," + oFloat.offsetHeight; /*****************/ /*计算出滑块的left,top*/ var l = oEvent.clientX - oSmall.offsetLeft - oFloat.offsetWidth / 2; var t = oEvent.clientY - oSmall.offsetTop - oFloat.offsetHeight / 2; if (l < 0) { l = 0 } else if (l > oSmall.offsetWidth - oFloat.offsetWidth) { l = oSmall.offsetWidth - oFloat.offsetWidth } if (t < 0) { t = 0 } else if (t > oSmall.offsetHeight - oFloat.offsetWidth) { t = oSmall.offsetHeight - oFloat.offsetHeight; } oFloat.style.left = l + 'px'; oFloat.style.top = t + 'px'; zb.innerHTML = zb.innerHTML + "<br/>" + l + "," + t; //计算出相对百分比 var percentX = l / (oSmall.offsetWidth - oFloat.offsetWidth); var percentY = t / (oSmall.offsetHeight - oFloat.offsetHeight); oImg.style.left = -percentX * (oBig.offsetWidth) + 'px'; oImg.style.top = -percentY * (oBig.offsetHeight) + 'px'; } })(); </script> </body></html>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
拓展知识
主要使用了document对象关于窗口的一些属性,这些属性的主要功能和用法如下。要 得到窗口的尺寸,对于不同的浏览器,需要使用不同的属性和方法:若要检测窗口的真实尺寸,在netscape下需要使用window的属性;在ie下需 要深入document内部对body进行检测;在dom环境下,若要得到窗口的尺寸,需要注意根元素的尺寸,而不是元素。window对象的innerwidth属性包含当前窗口的内部宽度。window对象的innerheight属性包含当前窗口的内部高度。document对象的body属性对应html文档的标签。document对象的documentelement属性则表示html文档的根节点。document.body.clientheight表示html文档所在窗口的当前高度。document.body. clientwidth表示html文档所在窗口的当前宽度。js获取屏幕高度var s = ""; s += " 网页可见区域宽:"+ document.body.clientwidth;s += " 网页可见区域高:"+ document.body.clientheight; s += " 网页可见区域宽:"+ document.body.offsetwidth +" (包括边线和滚动条的宽)"; s += " 网页可见区域高:"+ document.body.offsetheight +" (包括边线的宽)"; s += " 网页正文全文宽:"+ document.body.scrollwidth; s += " 网页正文全文高:"+ document.body.scrollheight; s += " 网页被卷去的高:"+ document.body.scrolltop; s += " 网页被卷去的左:"+ document.body.scrollleft; s += " 网页正文部分上:"+ window.screentop; s += " 网页正文部分左:"+ window.screenleft; s += " 屏幕分辨率的高:"+ window.screen.height; s += " 屏幕分辨率的宽:"+ window.screen.width; s += " 屏幕可用工作区高度:"+ window.screen.availheight; s += " 屏幕可用工作区宽度:"+ window.screen.availwidth; s += " 你的屏幕设置是 "+ window.screen.colordepth +" 位彩色"; s += " 你的屏幕设置 "+ window.screen.devicexdpi +" 像素/英寸";好文要顶 关注我 收藏该文
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
给我老师的人工智能教程打call!http://blog.youkuaiyun.com/jiangjunshow
