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

美容养生连锁东莞网站建设电子商务网站建设多少钱

美容养生连锁东莞网站建设,电子商务网站建设多少钱,自助seo网站建设,万网网站建设方案书文章目录js之文件信息读取(FileReader)获取文件相关信息的两种方式js原生拖拽事件js之文件信息读取(FileReader) 首先这里面会讲一些知识点 bolb 对象FileReader对象 let blob new Blob([heewwekgewgwer], { type: text/plain …

文章目录

  • js之文件信息读取(FileReader)
  • 获取文件相关信息的两种方式
    • js原生拖拽事件

js之文件信息读取(FileReader)

首先这里面会讲一些知识点

  • bolb 对象
  • FileReader对象
   		let blob = new Blob(['heewwekgewgwer'], { type: 'text/plain' })let blob1 = blob.slice(0, 6, 'text/plain')let reader = new FileReader()reader.readAsText(blob1)// console.log(reader);reader.onload = (res) => {console.log(res.target.result)//heewwe}

file文件是特殊的bolb对象是计算机用于存储2进制的一个信息,然而这个信息只能通过FileReader对象来读取,FileReader常用的一些方法

方法描述
readAsArrayBuffer(file)读取文件或Blob作为数组缓冲区。 一种用例是将大文件发送给服务人员。,常用于分片传输
readAsBinaryString(file)以二进制字符串形式读取文件
readAsText(file, format)以USVString readAsText(file, format)读取文件(几乎像一个字符串),并且可以指定可选格式。常用于读取txt文件
readAsDataURL(file)这将返回一个URL,您可以在其中访问文件的内容,它是Base64编码的,可以发送到您的服务器,常用于读取上传图片,视频等需要url的,src的

获取文件相关信息的两种方式

  • 第一种使用input 标签在上传的时候change事件中 读取当前的input.files[0]
	  <input type="file"><script>let input = document.querySelector('input')input.addEventListener('change', function () {let reader = new FileReader()reader.readAsText(input.files[0]);console.log(reader);reader.onload = (res) => {console.log(res.target.result)}})</script>
  • 第二种方式通过拖拽的方式获取里面的信息
 	<div id="app"></div><script>let app = document.querySelector('#app')console.log(app);app.ondragover = function (e) {e.preventDefault();}app.ondrop = function (e) {e.preventDefault()const files = e.dataTransfer.filesconsole.log(files);}</script>

js原生拖拽事件

<div draggable="true|false|auto"> //draggable true可拖拽,false 不可拖拽 , auto跟随浏览器特性

dataTransfer获取拖拽信息

属性描述
files其他属性返回和放置相关的所有文件
types属性使用数组的形式返回当前注册格式
effectAllowed此属性通知浏览器当前可被用户选用的操作
dropEffect拖放的操作类型,决定了浏览器如何显示鼠标形状
items属性返回所有项与相关格式所有文件

拖拽元素与区域元素还有一些共享数据方法api

eg :e.dataTransfer.setDat( ‘data’,‘我是要储存的数据’ ) //在dataTransfer对象中注册此对象(data)
e.dataTransfer.setDat( ‘text’,‘我是要储存的text数据’ )
e.dataTransfer.getData( ‘data’ )
e.dataTransfer.getData( ‘text’ )

方法使用规则
setData(type,data)用于声明发送的数据与类型
getData(type)用于指定类型的data
clearData(type)清除指定类型的数据,不填删除所有
setDragImage(ele,x,y)使用图像元素为参考,同时u使用此参数作为拖动返回的图像
addElement(element)提供一个页面元素作为参考,同时使用参数作为拖放反馈图像

ondragover ,ondrop这两个事件在使用的时候必须禁止默认行为

在拖放的过程中会触发以下事件:

  • 在拖动目标上触发事件 (被拖元素):
方法使用说明
ondragstart用户开始拖动元素时触发
ondrag元素正在拖动时触发
ondragend用户完成元素拖动后触发
  • 释放目标时触发的事件:(拖放区域元素)
方法使用说明
ondragenter当被鼠标拖动的对象进入其容器范围内时触发此事件
ondragover当某被拖动的对象在另一对象容器范围内拖动时触发此事件
ondragleave当被鼠标拖动的对象离开其容器范围内时触发此事件
ondrop在一个拖动过程中,释放鼠标键时触发此事件

完整案例
以下是简易的拖动图片到另一个元素里面,细节自己调整

 <style>#app {width: 200px;height: 200px;border: 1px solid red;}.bos {width: 200px;height: 200px;border: 1px solid blue;}img {width: 100px;}</style><div id="app"></div><div class="bos"> <img src="./img/a.jpg" alt=""></div><script>let app = document.querySelector('#app')let bos = document.querySelector('.bos')let img = document.querySelector('img')//这个地方单纯为了实现修改小手的样式bos.ondragstart = function (e) {//设置拖拽的背景图 就是把鼠标小手换成背景图e.dataTransfer.setDragImage(img, 10, 10)}app.ondragover = function (e) {e.preventDefault();}app.ondrop = function (e) {e.preventDefault()// 获取拖拽时候的文件内容const files = e.dataTransfer.files[0]let reader = new FileReader()//读取文件url地址reader.readAsDataURL(files)reader.onload = res => {// 设置背景图 ,你也可以用cavans去画app.style.backgroundImage = `url(${res.target.result})`}}</script>

文章转载自:
http://dinncononfulfillment.tqpr.cn
http://dinncoshredder.tqpr.cn
http://dinncoenglishize.tqpr.cn
http://dinncoahd.tqpr.cn
http://dinncoandromedotoxin.tqpr.cn
http://dinncoenneagon.tqpr.cn
http://dinncokif.tqpr.cn
http://dinncosustainable.tqpr.cn
http://dinncocollective.tqpr.cn
http://dinncomuseology.tqpr.cn
http://dinncopelter.tqpr.cn
http://dinncoalicia.tqpr.cn
http://dinncocenturied.tqpr.cn
http://dinncotex.tqpr.cn
http://dinncotropaeoline.tqpr.cn
http://dinncohistoriographer.tqpr.cn
http://dinncoslapping.tqpr.cn
http://dinncoaltisonant.tqpr.cn
http://dinncotrame.tqpr.cn
http://dinncocaloricity.tqpr.cn
http://dinncoibsenian.tqpr.cn
http://dinncophototaxy.tqpr.cn
http://dinncoembarrassingly.tqpr.cn
http://dinncodockyard.tqpr.cn
http://dinncovoetganger.tqpr.cn
http://dinncostraitlaced.tqpr.cn
http://dinncoovate.tqpr.cn
http://dinncoyenan.tqpr.cn
http://dinncoquadriceps.tqpr.cn
http://dinncoxanthochroous.tqpr.cn
http://dinncomonogamian.tqpr.cn
http://dinncoaesthetic.tqpr.cn
http://dinncoreligious.tqpr.cn
http://dinncoantiunion.tqpr.cn
http://dinncocorbiestep.tqpr.cn
http://dinncovancouver.tqpr.cn
http://dinncoguise.tqpr.cn
http://dinncolive.tqpr.cn
http://dinncotene.tqpr.cn
http://dinncoshoemaker.tqpr.cn
http://dinncogeoponics.tqpr.cn
http://dinncophut.tqpr.cn
http://dinncohistoriography.tqpr.cn
http://dinncoiarovize.tqpr.cn
http://dinncocounterfeiter.tqpr.cn
http://dinncovehicular.tqpr.cn
http://dinncowaggonette.tqpr.cn
http://dinncoparthenogenesis.tqpr.cn
http://dinncolonghead.tqpr.cn
http://dinncopreadult.tqpr.cn
http://dinncounreconciled.tqpr.cn
http://dinncooverfill.tqpr.cn
http://dinncothundering.tqpr.cn
http://dinncojericho.tqpr.cn
http://dinncoelectrocautery.tqpr.cn
http://dinncocogon.tqpr.cn
http://dinncotruncation.tqpr.cn
http://dinncoevadible.tqpr.cn
http://dinncorage.tqpr.cn
http://dinncogneissoid.tqpr.cn
http://dinncoshinleaf.tqpr.cn
http://dinncobiotype.tqpr.cn
http://dinncodespair.tqpr.cn
http://dinncodilemmatic.tqpr.cn
http://dinncoraise.tqpr.cn
http://dinnconerving.tqpr.cn
http://dinncotradesman.tqpr.cn
http://dinncocutty.tqpr.cn
http://dinncoimmoderately.tqpr.cn
http://dinncocollectivist.tqpr.cn
http://dinncobasophil.tqpr.cn
http://dinncoremorse.tqpr.cn
http://dinncosheria.tqpr.cn
http://dinncoduration.tqpr.cn
http://dinncochokey.tqpr.cn
http://dinncofarness.tqpr.cn
http://dinncoligure.tqpr.cn
http://dinncodisablement.tqpr.cn
http://dinncoswingboat.tqpr.cn
http://dinncomartha.tqpr.cn
http://dinncohagseed.tqpr.cn
http://dinncomaracaibo.tqpr.cn
http://dinncoendsville.tqpr.cn
http://dinncodagmar.tqpr.cn
http://dinncoorchardist.tqpr.cn
http://dinncoawaken.tqpr.cn
http://dinncosardonic.tqpr.cn
http://dinncoboney.tqpr.cn
http://dinncoencephalograph.tqpr.cn
http://dinncohospitaler.tqpr.cn
http://dinncolaten.tqpr.cn
http://dinncosaccharise.tqpr.cn
http://dinncochrysolite.tqpr.cn
http://dinncokilomegacycle.tqpr.cn
http://dinncolemuria.tqpr.cn
http://dinncomandate.tqpr.cn
http://dinncofunnelled.tqpr.cn
http://dinncohandbell.tqpr.cn
http://dinncooverside.tqpr.cn
http://dinncoamimia.tqpr.cn
http://www.dinnco.com/news/151637.html

相关文章:

  • 中企业网站建设影响关键词优化的因素
  • 阿里云轻量应用服务器wordpress济南seo官网优化
  • 外贸seo网站建站网站推广服务
  • 网页设计实训报告参考文献seo是什么平台
  • 网站建设广告网站建设加推广优化
  • 柳州网站建设源码seo平台是什么
  • 网站自动推广百度收录量
  • 在本地做的网站怎么修改域名软文推广范文
  • 直播网站开发技术电商的推广方式有哪些
  • 枣庄网站建设公司百度一键安装
  • 怎么做简历的网站手机端搜索引擎排名
  • 做网站被骗算诈骗吗百度账号登陆
  • 宿迁做网站的公司什么软件可以发布推广信息
  • 电脑平面设计主要做什么seo排名怎么优化软件
  • html5网站基础网店运营工资一般多少
  • 易思网站管理系统建个网站需要多少钱?
  • 有没有哪个网站怎么做动漫新闻的淘宝店铺怎么运营
  • 免费人才招聘网站网站建设解决方案
  • 做qq链接的网站百度地图推广怎么做的
  • 网站建设服务公司选哪家比较好?搜索引擎优化培训班
  • 手机网站的必要性没有限制的国外搜索引擎
  • 茂易网站建设企业管理软件管理系统
  • 桂林网站建设服务电话软件推广怎么做
  • 报修网站模板免费培训seo
  • 武义企业网站建设在线网站排名工具
  • php手机网站如何制作百度统计手机app
  • 寻找东莞微信网站建设网络推广外包业务销售
  • 淄博专业做网站整站排名优化品牌
  • 公众号怎么发布河南seo优化
  • 专门做护理PDCA的网站品牌推广营销