AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
[TOC] # 7.1 jQuery 尺寸 | 语法 | 用法 | | --- | --- | | width()/height() | 取得匹配元素宽度和高度值只算width 1 height | | innerWidth() / innerHieght() | 取得匹配元素宽度和高度值包含padding | | outerWidth() / outerHeight() | 取得匹配元素宽度和高度值包含padding、border | | outerWidth(true) / outerHeight(true) | 取得匹配元素宽度和高度值包含padding、borde、 margin | ~~~ ●以上参数为空,则是获取相应值,返回的是数字型。 ●如果参数为数字,则是修改相应值。 ●参数可以不必写单位。 ~~~ # 7.2 jQuery 位置 位置主要有三个:offset()、position()、 scrollTop() / scrolLeft() ## 1\. offset()设置或获取元素偏移 ①offset( 方法设置或返回被选元素相对于文档的偏移坐标,跟父级没有关系。 ②该方法有2个属性left. top. offset0.top 用于获取距离文档顶部的距离, ffset0.left用于获取距离文档左侧的距离。 ③可以设置元素的偏移: offset({ top: 10, left: 30}); ![](https://img.kancloud.cn/ca/ad/caad5325db6d560c0bc8c293ad8f7f49_833x307.png) ## 2\. position()获取元素偏移 ①position() 方法用于返回被选元素相对于带有定位的父级偏移坐标,如果父级都没有定位,则以文档为准。 ## 3\. scrollTop() / scrollLeft()设置或获取元素被卷去的头部和左侧 ![](https://img.kancloud.cn/60/57/605742d32a7f0d4f86e511067695688f_577x493.png) ①scrollTop() 方法设置或返回被选元素被卷去的头部。 ![](https://img.kancloud.cn/40/5e/405e1c752b4589fd19551b4a12227c0f_976x579.png) # 案例:带有动画的返回顶部 ①核心原理:使用animate动画返回顶部。 ②animate动画函数里面有个scrollITop 属性,可以设置位置 ③但是是元素做动画,因此$( "body,html" ).animate({scrolITop: 0}) ![](https://img.kancloud.cn/40/5e/405e1c752b4589fd19551b4a12227c0f_976x579.png) ![](https://img.kancloud.cn/b7/b1/b7b1b5f469863c3306b3f68b4c74a989_750x353.png) # 2.案例:品优购电梯导航 ![](https://img.kancloud.cn/49/0f/490fc0164f77d8caa268a174ea970f06_977x409.png) html ![](https://img.kancloud.cn/44/b5/44b596f1fd2210c81b4f8510232a8ee7_679x314.png) ![](https://img.kancloud.cn/06/9e/069eea7916ba3e40a4bcda74876c38c0_550x420.png) ## 代码实验 ![](https://img.kancloud.cn/d8/c3/d8c3388abe2c7cb4d56572a146baf791_850x261.png) 1.![](https://img.kancloud.cn/8b/d6/8bd6db1583ccb87a2d96fd607539844b_812x401.png)1.优化版![](https://img.kancloud.cn/f2/1a/f21a1ca3688714556a57f48b74d39587_903x516.png) 2.![](https://img.kancloud.cn/d4/9b/d49b4cdc9c01fb290d6e4331ad1bc827_1014x377.png)2.优化版 ![](https://img.kancloud.cn/64/53/645337a8b52f2c1d7f0005928fd3edbf_1198x447.png) 3.当前页面滚动 ,电梯导航也跟着发生变化 ![](https://img.kancloud.cn/bd/3b/bd3b2426742278d58489e9856ccfd824_1202x343.png) ![](https://img.kancloud.cn/5a/91/5a912d68a138037c9dbada1b49c5998b_1262x409.png) 4.页面优化,节流阀,互斥锁 ![](https://img.kancloud.cn/a0/8c/a08c3d1db7231affc4ca0671eeb4e26c_1192x706.png) ![](https://img.kancloud.cn/61/03/610364dfdc75dd8b1bab5b4d23ad8410_1265x523.png) ![](https://img.kancloud.cn/71/98/7198d7007634abfdb5abb62a0d213c74_1038x561.png)