当前位置: 首页 > news >正文

nas有域名了怎么做网站一线城市网站建设费用高

nas有域名了怎么做网站,一线城市网站建设费用高,做网站一般多少钱,百度搜不到WordPress文章学习目标: 掌握元素尺寸与位置 学习内容: 元素尺寸与位置仿京东固定导航栏案例实现bilibili点击小滑块移动效果 元素尺寸与位置: 使用场景: 前面案例滚动多少距离,都是我们自己算的,最好是页面滚动到某个…

学习目标:

  • 掌握元素尺寸与位置

学习内容:

  1. 元素尺寸与位置
  2. 仿京东固定导航栏案例
  3. 实现bilibili点击小滑块移动效果

元素尺寸与位置:

  • 使用场景:

前面案例滚动多少距离,都是我们自己算的,最好是页面滚动到某个元素,就可以做某些事。

简单说,就是通过js的方式,得到元素在页面中的位置

这样我们可以做,页面滚动到这个位置,就可以做某些操作,省去计算了。
在这里插入图片描述

  • 获取宽高:

获取元素的自身宽高、包含元素自身设置的宽高、padding、border

offsetWidth和offsetHeight

获取出来的是数值,方便计算。

注意:获取的是可视宽高,如果盒子是隐藏的,获取的结果是0。

  • 获取位置:
  1. offsetLeft和offsetTop 注意是只读属性

获取元素距离自己定位父级元素的左、上距离。

在这里插入图片描述

 <title>offsetLeft</title><style>div {position: relative;width: 200px;height: 200px;background: pink;margin: 100px;}p {width: 100px;height: 100px;background: purple;margin: 50px;}</style>
</head><body><div><p></p></div><script>const div = document.querySelector('div')const p = document.querySelector('p')// console.log(div.offsetLeft)//检测盒子的位置  最近一级带有定位的祖先元素console.log(p.offsetLeft)</script></body>
  1. element.getBoundingClientRect()

方法返回元素大小及其相对于视口的位置。

在这里插入图片描述

 <title>获取元素大小位置的另外方法</title><style>body {height: 2000px;}div {width: 200px;height: 200px;background: pink;margin: 100px;}</style>
</head><body><div></div><script>const div = document.querySelector('div')console.log(div.getBoundingClientRect())</script></body>
  • 小结
  1. offsetWidthoffsetHeight是得到元素什么的宽高?

     内容 + padding + border
    
  2. offsetTopoffsetLeft得到位置以谁为准?

    带有定位的父级
    如果都没有则以文档左上角为准
    
属性作用说明
scrollLeftscrollTop 被卷去的头部和左侧配合页面滚动来用,可读写
clientWidthclientHeight获得元素宽度和高度不包含border、margin,滚动条 ,用于js获取元素大小,只读属性
offsetWidthoffsetHeight获得元素宽度和高度包含border、margin,滚动条,只读
offsetTopoffsetLeft获取元素距离自己定位父级元素的左、上距离获取元素位置的时候使用,只读属性

仿京东固定导航栏案例:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>练习-仿京东固定导航栏案例</title><style>* {margin: 0;padding: 0;box-sizing: border-box;}.content {overflow: hidden;width: 1000px;height: 3000px;background-color: pink;margin: 0 auto;}.backtop {display: none;width: 50px;left: 50%;margin: 0 0 0 505px;position: fixed;bottom: 60px;z-index: 100;}.backtop a {height: 50px;width: 50px;background: url(./images/bg2.png) 0 -600px no-repeat;opacity: 0.35;overflow: hidden;display: block;text-indent: -999em;cursor: pointer;}.header {position: fixed;top: -80px;left: 0;width: 100%;height: 80px;background-color: purple;text-align: center;color: #fff;line-height: 80px;font-size: 30px;transition: all .3s;}.sk {width: 300px;height: 300px;background-color: skyblue;margin-top: 500px;}</style>
</head><body><div class="header">我是顶部导航栏</div><div class="content"><div class="sk">秒杀模块</div></div><div class="backtop"><img src="./images/close2.png" alt=""><a href="javascript:;"></a></div><script>const sk = document.querySelector('.sk')const header = document.querySelector('.header')//1.页面滚动事件window.addEventListener('scroll', function () {//当页面滚动到 秒杀模块的时候,就改变头部的top值//页面被卷去的头部 >= 秒杀模块的位置  offsetTopconst n = document.documentElement.scrollTop// if (n >= sk.offsetTop) {//   header.style.top = 0// } else {//   header.style.top = '-80px'// }header.style.top = n >= sk.offsetTop ? 0 : '-80px'})</script></body></html>

实现bilibili点击小滑块移动效果:

<style>.line {transition: all .3s;}</style><script>//1.获取父元素 添加事件委托const list = document.querySelector('.tabs-list')const line = document.querySelector('.line')//2.给a注册事件list.addEventListener('click', function (e) {//判断点击的是aif (e.target.tagName === 'A') {// console.log(11)//得到当前链接的  offsetLeft// console.log(e.target.offsetLeft)//让line 盒子来进行移动line.style.transform = `translateX(${e.target.offsetLeft}px)`}})</script>
http://www.yayakq.cn/news/37364/

相关文章:

  • 国外vps做网站测速有什么做兼职的医疗网站
  • 嘉兴高端网站外贸网站空间选择
  • 青岛外贸网站建设费用专业网站设计
  • 网站系统 外贸网站建设宣传语
  • 哪里有门户网站开发公司蚌埠网站制作公司哪家好
  • 网站服务器是什么企业培训课程分类
  • 西安网站建设公司西安网络公司卖源码的网站
  • 自己怎么注册一个网站wordpress调用post的发布时间
  • 微山本地有做网站的么做外贸阿里巴巴有哪些网站
  • 网站建设捌金手指花总四ssh小型购物网站开发
  • 音乐网站还可以做唐山建设集团下岗职工网站
  • 怎么做网站商城wordpress修改链接出现404
  • 网站域名批量查询注册洛阳瀍河建设局网站
  • 重庆做网站哪个好些嘛海口装饰设计网站建设
  • 小白建站软件山西省住房和城乡建设厅网站
  • 福州市交通建设集团有限公司网站什么是优化产业结构
  • 网站建设 验收商业网站建设者
  • 深圳网站建设认准乐云践新搜索引擎优化有哪些
  • 浦口区网站建设质量推荐有哪些做的比较精美的网站
  • 一分钟建站wordpress 用的什么框架
  • 电子商务网站建设与管理实训心得设计兼职网站有哪些
  • 辽宁天一建设有限责任公司网站百度链接收录
  • 做购物网站小图标河北石家庄
  • php网站忘记后台密码六安网站制作多少钱
  • 怎么在360网站做词条湿地公园网站开发招标
  • 有免费的微网站是什么桐城网站设计
  • 医药公司网站建设备案优秀产品设计案例分析
  • 怎么对企业进行网站建设有什么网站是学做吃的
  • 企业建设营销型网站的目的有网站管理系统排名
  • 网站设计 北京 010西地那非的危害