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

数据库2008做企业网站什么是新媒体营销

数据库2008做企业网站,什么是新媒体营销,建中英文网站,国内专业网站建设公司学习目标: 掌握元素尺寸与位置 学习内容: 元素尺寸与位置仿京东固定导航栏案例实现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.mmbaike.com/news/55746.html

相关文章:

  • 做网站要素2022年度关键词
  • 怎么做商务网站的架构seo如何优化一个网站
  • 最优网络是做网站的吗舆情信息
  • 有哪些网站有收录做红酒的商行谷歌seo查询
  • WordPress来必力seo外包服务公司
  • 网站图片优化怎么做微信小程序官网
  • 手机网站和微网站百度推广的方式有哪些
  • 怎样创办网站云盘网页版登录
  • 公司翻译网站seo搜索
  • 陕西省建设厅网站三类b证百度竞价排名危机事件
  • 丰宁县网站建设搜索引擎优化是指什么
  • 做公司网站有什么需要注意的数据分析师证书
  • 广州制作软件seo公司上海
  • 政府网站建设的意义营销手机系统安装
  • 网站续费管理系统长沙网站推广和优化
  • wordpress 方法排名优化网站
  • 网站地图怎么做html谷歌官网网址
  • 4s店网站模板太原搜索引擎优化
  • 电子商务网站系统建设进度安排在线咨询 1 网站宣传
  • 做住宿的网站能翻到国外的浏览器
  • 做网站公司做网站公司有哪些百度一下图片识别
  • 网站如何规范的排版编辑外链网站推荐
  • 手机怎么使用代理ip上网常州网站优化
  • 网站access数据怎么做专业的网站建设公司
  • 企业网站管理系统asp重庆百度推广关键词优化
  • 长沙专业网站建设站长网站查询
  • 北京做一个网站多少钱推广网址
  • 备案中又需要建设网站深圳网站开发制作
  • 网站编辑工具刷关键词排名seo
  • 怎么用dw做可上传文件的网站外贸推广平台哪家好