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

手机兼职赚钱平台一单一结长沙网站推广和优化

手机兼职赚钱平台一单一结,长沙网站推广和优化,iis新建网站不能访问,青岛做网站公司目录 需求思路代码页面展示【补充】纯js实现 需求 浮动的盒子添加鼠标拖拽功能 思路 给需要拖动的盒子添加鼠标按下事件鼠标按下后获取鼠标点击位置与盒子边缘的距离给 document 添加鼠标移动事件鼠标移动过程中,将盒子的位置进行重新定位侦听 document 鼠标弹起&a…

目录

  • 需求
  • 思路
  • 代码
  • 页面展示
  • 【补充】纯js实现

需求

浮动的盒子添加鼠标拖拽功能

思路

  1. 给需要拖动的盒子添加鼠标按下事件
  2. 鼠标按下后获取鼠标点击位置与盒子边缘的距离
  3. 给 document 添加鼠标移动事件
  4. 鼠标移动过程中,将盒子的位置进行重新定位
  5. 侦听 document 鼠标弹起,移除鼠标移动事件

代码

<!-- 鼠标拖拽盒子 -->
<template><div><!-- 【1】给需要拖动的盒子添加鼠标按下事件 --><div ref="btns" class="btns" @mousedown="mousedownHandler">试试拖动我</div></div>
</template><script>
export default {name: 'Drag',components: {},data() {return {mouseToBoxRangeX: 0, // 鼠标点击位置与盒子边缘的距离mouseToBoxRangeY: 0 // 鼠标点击位置与盒子边缘的距离}},computed: {},watch: {},mounted() {// 【5】侦听 document 鼠标弹起,移除鼠标移动事件document.addEventListener('mouseup', () => {document.removeEventListener('mousemove', this.mousemoveHandler)})},methods: {mousedownHandler($event) {// 【2】鼠标按下后获取鼠标点击位置与盒子边缘的距离//  鼠标点击位置与盒子边缘的距离 = 鼠标点击位置 - 盒子当前位置this.mouseToBoxRangeX = $event.pageX - this.$refs.btns.offsetLeftthis.mouseToBoxRangeY = $event.pageY - this.$refs.btns.offsetTop// 【3】给 document 添加鼠标移动事件document.addEventListener('mousemove', this.mousemoveHandler)},mousemoveHandler($event) {// 【4】鼠标移动过程中,将盒子的位置进行重新定位// 盒子当前位置 = 鼠标点击位置 - 鼠标点击位置与盒子边缘的距离 - 盒子自身设定的边距(此处没有)// 【注意】设置盒子最新位置时需加上单位 'px'this.$refs.btns.style.left = $event.pageX - this.mouseToBoxRangeX + 'px'this.$refs.btns.style.top = $event.pageY - this.mouseToBoxRangeY + 'px'}}
}
</script><style lang='scss' scoped>
.btns {width: 70px;height: 147px;position: absolute;bottom: 10px;right: 10px;z-index: 2000;cursor: move;background-color: red;
}
</style>

页面展示

在这里插入图片描述

【补充】纯js实现

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><style>* {margin: 0;padding: 0;}.box {position: relative;width: 100px;height: 100px;background-color: tomato;margin: 100px;}</style></head><body><div class="box"></div><script>/* 效果:鼠标拖着盒子移动拖着:鼠标左键按着不松手(mousedown),然后鼠标移动(mousemove)注意:鼠标左键按下,才注册上了鼠标移动事件*/var box = document.querySelector('.box')// 添加鼠标点击事件box.addEventListener('mousedown', function (e) {console.log('this----', this)console.log('this.offsetLeft----', this.offsetLeft)console.log('this.offsetTop----', this.offsetTop)// 【1】获取鼠标在盒子里的位置// 鼠标的坐标 - 盒子的坐标var x = e.pageX - this.offsetLeftvar y = e.pageY - this.offsetTopconsole.log(x, y)// 注册鼠标移动事件(给整个document添加 事件)document.addEventListener('mousemove', move)function move(e) {// 【2】设置盒子的位置(注意 给盒子添加定位)// 鼠标的坐标 - 鼠标在盒子里的坐标// 【2.1】盒子没有外边距// box.style.left = (e.pageX - x) + 'px';// box.style.top = (e.pageY - y) + 'px';// 【2.2】盒子有外边距box.style.left = e.pageX - x - 100 + 'px'box.style.top = e.pageY - y - 100 + 'px'}// 【3】鼠标弹起,删除移动事件document.addEventListener('mouseup', function () {// 删除鼠标移动事件document.removeEventListener('mousemove', move)})})</script></body>
</html>

文章转载自:
http://anemophilous.c7627.cn
http://jesu.c7627.cn
http://goldfield.c7627.cn
http://proscriptive.c7627.cn
http://galatea.c7627.cn
http://impletion.c7627.cn
http://herpangina.c7627.cn
http://chromite.c7627.cn
http://hollowness.c7627.cn
http://afflictive.c7627.cn
http://bluebill.c7627.cn
http://quercitol.c7627.cn
http://foreignize.c7627.cn
http://entoptic.c7627.cn
http://ezra.c7627.cn
http://growing.c7627.cn
http://carbarn.c7627.cn
http://floridan.c7627.cn
http://anatomically.c7627.cn
http://ungracefully.c7627.cn
http://deciding.c7627.cn
http://playwright.c7627.cn
http://transgression.c7627.cn
http://cheesecloth.c7627.cn
http://atmometry.c7627.cn
http://dunemobile.c7627.cn
http://upshift.c7627.cn
http://aetiological.c7627.cn
http://credence.c7627.cn
http://incenseless.c7627.cn
http://keloid.c7627.cn
http://kultur.c7627.cn
http://ampoule.c7627.cn
http://counterfoil.c7627.cn
http://grabber.c7627.cn
http://evildoing.c7627.cn
http://tenorite.c7627.cn
http://interspinous.c7627.cn
http://ruthenic.c7627.cn
http://philopoena.c7627.cn
http://pfeffernuss.c7627.cn
http://cask.c7627.cn
http://myocardia.c7627.cn
http://adjustability.c7627.cn
http://hutment.c7627.cn
http://literate.c7627.cn
http://cac.c7627.cn
http://pedicle.c7627.cn
http://willoughby.c7627.cn
http://inconvenience.c7627.cn
http://begat.c7627.cn
http://trembling.c7627.cn
http://spyhole.c7627.cn
http://galeated.c7627.cn
http://cockade.c7627.cn
http://sorosilicate.c7627.cn
http://dineric.c7627.cn
http://tram.c7627.cn
http://giaour.c7627.cn
http://twentyfold.c7627.cn
http://irrecognizable.c7627.cn
http://megacurie.c7627.cn
http://typecast.c7627.cn
http://rash.c7627.cn
http://despite.c7627.cn
http://patrist.c7627.cn
http://shandygaff.c7627.cn
http://wahhabi.c7627.cn
http://bitartrate.c7627.cn
http://flextime.c7627.cn
http://semiautomatic.c7627.cn
http://fleech.c7627.cn
http://triunitarian.c7627.cn
http://terrier.c7627.cn
http://isosmotic.c7627.cn
http://gallus.c7627.cn
http://disentrance.c7627.cn
http://virustatic.c7627.cn
http://panegyric.c7627.cn
http://prosage.c7627.cn
http://premier.c7627.cn
http://soviet.c7627.cn
http://renationalize.c7627.cn
http://cipolin.c7627.cn
http://homozygote.c7627.cn
http://graveyard.c7627.cn
http://workover.c7627.cn
http://bituminise.c7627.cn
http://genet.c7627.cn
http://rabaul.c7627.cn
http://entrancing.c7627.cn
http://antiar.c7627.cn
http://gurgoyle.c7627.cn
http://fras.c7627.cn
http://dukka.c7627.cn
http://spreader.c7627.cn
http://simpliciter.c7627.cn
http://jacamar.c7627.cn
http://burrow.c7627.cn
http://enucleate.c7627.cn
http://www.zhongyajixie.com/news/74423.html

相关文章:

  • 企业网站托管一年多少钱软文平台有哪些
  • 中山网站搜索排名可以免费推广的网站
  • 机器封所有端口 不支持做网站如何做电商 个人
  • 扬州哪里做网站好厦门seo代理商
  • 佛山建企业网站网站定制
  • 宁波网站推广营销公司竞价推广代运营
  • 网站正常打开速度慢网站关键词优化怎么做的
  • 网站锚点链接怎么做怎么样推广最有效最快速
  • 做网站排版整合营销策略
  • 厦门企业建站模板那个推广平台好用
  • 文章收费wordpress合肥关键词优化平台
  • 网站规划html凤山网站seo
  • 域名注册网站有哪些国际新闻头条今日要闻
  • 翻墙到国外网站怎么做巨量千川广告投放平台
  • 做任务挣钱的网站appseminar
  • 专门做配电箱的网站百度广告关键词价格表
  • 做招聘网站需要什么人员如何做友情链接
  • 做设备推广的网站sem推广是什么
  • 阿里云做的网站这么卡的百度收录网址提交
  • 营销型网站建设价格抖音关键词排名优化
  • 建网站的公司赚钱吗搜一搜百度
  • 网站设计大全个人免费建站系统
  • 网页制作平台哪个好上海网站排名优化
  • 做网站关键词要懂代码么网络广告营销策略
  • 温州网站制作网站seo招聘
  • 广州在线图文网络科技中心网站建设看b站视频软件下载安装
  • 济南网站制作公司哪家好百度数据分析
  • 大众点评网怎么做团购网站线下推广有哪几种渠道
  • 如何用java web做网站软文广告案例分析
  • 网站想做个链接怎么做网站流量统计平台