dom

React-虚拟DOM

…衆ロ難τιáo~ 提交于 2020-02-06 11:53:45
先举个例子: import React from 'react' import ReactDOM from 'react-dom' let myRender = ( ) => { let el = ( < div > < h1 > 虚拟 DOM < / h1 > < p > { new Date ( ) . toLocaleString ( ) } < / p > < / div > ) ReactDOM . render ( el , document . getElementById ( 'root' ) ) } // 定时器每 1 秒执行一次 setInterval ( myRender , 1000 ) 打开浏览器控制台,在 Elements 中会发现,只有数据改变的部分 DOM 才会进行更新;是因为在 react 中,数据发生改变时是通过虚拟 DOM 更新的;当数据发生改变时,会用最新的数据去修改模板形成新的虚拟 DOM,新的虚拟 DOM 和旧的 虚拟DOM 通过 diff 算法进行比较找到需要更新的地方进行更新 Diff 算法 在 React 中有两种假设: 两个不同类型的元素会产生不同的树 开发者可以通过 key 属性指定不同树中没有发生改变的子元素 Diff 算法说明 如果两棵 DOM 树的根元素类型不同,React 会销毁旧树,创建新的 DOM 树。

编程范式:命令式编程(Imperative)、声明式编程(Declarative)和函数式编程(Functional)

和自甴很熟 提交于 2020-02-06 09:41:23
一、简介 Vue是什么 Vue是一个当前流行的前端框架 Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架。与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用。Vue 的核心库只关注视图层,不仅易于上手,还便于与第三方库或既有项目整合。另一方面,当与 现代化的工具链 以及各种 支持类库 结合使用时,Vue 也完全能够为复杂的单页应用提供驱动。 渐进式框架 笔者理解的“渐进式框架”也非常简单,就是用你想用或者能用的功能特性,你不想用的部分功能可以先不用。 VUE不强求你一次性接受并使用它的全部功能特性。 场景一:公司刚开始一个项目,技术人员对Vue的掌握也不足够。那么我们就不能使用VUE了么?当然不是,如果你只是使用VUE做些 基础操作,如:页面渲染、表单处理提交功能,那还是非常简单的,成熟技术人员上手也就一两天。完全可以用它去代替jquery。并不需要你去引入其他复杂特性功能。 场景二:我们项目用了VUE,使用的效果也挺好。那么我们想逐渐实现代码组件化,实现代码的复用,或者是基于组件原型的跨项目的代码复用。那么我们就可以引入VUE的components组件特性了。 场景三:我们的项目规模逐渐的变大了,我们可能会逐渐用到前端路由、状态集中管理、并最终实现一个高度工程化的前端项目。这些功能特性我们可以逐步引入,当然不用也可以。

What is the difference between Window and window?

风流意气都作罢 提交于 2020-02-06 07:35:10
问题 What is Window ? Here's what I see on the console in Chrome : window Window {top: Window, window: Window, location: Location, external: Object, chrome: Object…} Window function Window() { [native code] } 回答1: Window is a function, as you can see. It's the constructor for the windows (but you can't build new windows directly with the constructor, you usually use the Window.open function). Window.prototype thus holds the methods you can call on the window). window is the global variable holding

Why does a <video> stop playing when removed from the DOM, while it can still play detached?

只愿长相守 提交于 2020-02-06 06:29:46
问题 I was working on a custom component and stumbled upon this strange behavior. Basically, it is possible to play a video file without adding a <video> element to the DOM at all. const video = document.createElement('video'); video.src = "https://upload.wikimedia.org/wikipedia/commons/transcoded/c/c6/Video_2017-03-19_23-01-33.webm/Video_2017-03-19_23-01-33.webm.480p.webm"; function start() { if (video.paused) { video.play(); console.log('paused', video.paused); } } <div><button onclick='start()'

Why does a <video> stop playing when removed from the DOM, while it can still play detached?

為{幸葍}努か 提交于 2020-02-06 06:28:45
问题 I was working on a custom component and stumbled upon this strange behavior. Basically, it is possible to play a video file without adding a <video> element to the DOM at all. const video = document.createElement('video'); video.src = "https://upload.wikimedia.org/wikipedia/commons/transcoded/c/c6/Video_2017-03-19_23-01-33.webm/Video_2017-03-19_23-01-33.webm.480p.webm"; function start() { if (video.paused) { video.play(); console.log('paused', video.paused); } } <div><button onclick='start()'

【前端】DOM事件模型

。_饼干妹妹 提交于 2020-02-06 02:31:32
https://www.w3.org/DOM/DOMTR.html 主要学习DOM level2 DOM level0: onclick(一旦用户点击,浏览器就执行onclick后的代码,要执行函数就需要记得带上’( )‘ 在html中写需要带上(),在js中写不需要() ) onerror、onload、onmouseenter DOM level2: elid.addEventListener('click',function(){ console.log(1); }) 和DOM 0 绑定方法区别: DOM 0 只可以绑定一个 DOM 2 可以绑定两个 xxx.onclick = function(){ console.log(1)// 有可能会覆盖之前xxx的点击事件 } 注:addEventListener绑定的事件是一个队列,先进先出,按顺序执行。 事件冒泡和事件捕获 注:浏览器默认冒泡 举例: yeye.addEventListener('click',function f1(){ console.log("爷爷") },false)//第二个参数不传入的话会传入undefined,逻辑上是falsey baba.addEventListener('click',function f2(){ console.log("父亲") },false) erzi

js Dom为页面中的元素绑定键盘或鼠标事件

淺唱寂寞╮ 提交于 2020-02-05 21:24:00
html鼠标事件 onload 页面加载 onclick 鼠标单击 onmouseover 鼠标移入 onmouseout 鼠标移出 onfocus 获取焦点 onblur 失去焦点 onchange 域的内容改变 在事件触发中,this表示对当前dom对象的引用 1、html事件,在html元素上直接绑定事件 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> .btn{ width:140px; height:30px; background:#abcdef; line-height:30px; text-align: center; font-size:14px; border-radius:5px; cursor:pointer; } div{ width:140px; height:140px; background:#abcdef; line-height:140px; text-align: center; font-size:14px; margin:50px 0; } </style> </head> <body> <button id="btn" class="btn" onclick="alert('我被点击啦!');"

JavaScript----章节二

随声附和 提交于 2020-02-05 17:07:05
5、内部对象 标椎对象 typeof 123 "number" typeof '123' "string" typeof true "boolean" typeof NaN "number" typeof [ ] "object" typeof { } "object" typeof Math . abs "function" typeof undefined "undefined" 5.1、Date 基本使用 var now = new Date ( ) ; //Sat Jan 04 2020 10:47:06 GMT+0800 (中国标准时间) now . getFullYear ( ) ; //年 now . getMonth ( ) ; // 月 0~11 代表月 now . getDate ( ) ; // 日 now . getDay ( ) ; // 星期几 now . getHours ( ) ; // 时 now . getMinutes ( ) ; // 分 now . getSeconds ( ) ; // 秒 now . getTime ( ) ; // 时间戳 全世界统一 1970 1.1 0:00:00 毫秒数 console . log ( new Date ( 1578106175991 ) ) //时间戳转为时间 转换 now = new Date

Why does DOMDocument::saveHTML()'s behavior differ in encoding UTF-8 as entities in style & script elements?

不打扰是莪最后的温柔 提交于 2020-02-05 07:15:14
问题 Given a DOMDocument constructed with a stylesheet that contains an emoji character like so: $dom = new DOMDocument(); $dom->loadHTML( "<!DOCTYPE html><html><head><meta charset=utf-8><style>span::before{ content: \"⚡️\"; }</style></head><body><span></span></body></html>" ); I've found some strange behavior when serializing the DOM back out to HTML. If I do $dom->saveHTML( $dom->documentElement ) then I get (as desired): <html><head><meta charset="utf-8"> <style>span::before{ content: "⚡️"; }<

How does Selenium click on elements that are 50% on screen and 50% not on screen?

与世无争的帅哥 提交于 2020-02-05 02:53:33
问题 There is a div-Element. 50% of its size are on the screen. The other 50% go over the screen height and are not visible. There is no scrolling possible. I tried to automate a test with Selenium and click on that div-element, but sometimes it works and sometimes it does not. Why does Selenium not just click on the "on-screen-area" of that div? And how is this functionality implemented? When I tell Selenium to click on a huge div-element, does it click on a random position on that div? 回答1: