window resize & resize observer

https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event

https://drafts.csswg.org/resize-observer-1/


<canvas id="elipse" style="display:block"></canvas>
<div id="menu" style="display:block;width:100px">
<img src="hamburger.jpg" style="width:24px;height:24px">
<p class="title">menu title</p>
</div>
// In response to resize, elipse paints an elipse inside a canvas
document.querySelector('#elipse').handleResize = entry => {
entry.target.width = entry.borderBoxSize.inlineSize;
entry.target.height = entry.borderBoxSize.blockSize;
let rx = Math.floor(entry.target.width / 2);
let ry = Math.floor(entry.target.height / 2);
let ctx = entry.target.getContext('2d');
ctx.beginPath();
ctx.ellipse(rx, ry, rx, ry, 0, 0, 2 * Math.PI);
ctx.stroke();
}
// In response to resize, change title visibility depending on width
document.querySelector('#menu').handleResize = entry => {
let title = entry.target.querySelector(".title")
if (entry.borderBoxSize.inlineSize < 40)
title.style.display = "none";
else
title.style.display = "inline-block";
} var ro = new ResizeObserver( entries => {
for (let entry of entries) {
let cs = window.getComputedStyle(entry.target);
console.log('watching element:', entry.target);
console.log(entry.contentRect.top,' is ', cs.paddingTop);
console.log(entry.contentRect.left,' is ', cs.paddingLeft);
console.log(entry.borderBoxSize.inlineSize,' is ', cs.width);
console.log(entry.borderBoxSize.blockSize,' is ', cs.height);
if (entry.target.handleResize)
entry.target.handleResize(entry);
}
});
ro.observe(document.querySelector('#elipse'));
ro.observe(document.querySelector('#menu'));

css resize

https://developer.mozilla.org/en-US/docs/Web/CSS/resize

js resize

https://codepen.io/xgqfrms/pen/dyyWrWb

react demo


import React, {
useState,
useEffect,
} from 'react'; import "./index.css"; import ChartTooltip from "./ChartTooltip";
import ChartBar from "./ChartBar";
import ChartPercentage from "./ChartPercentage"; const ChartBox = (props) => {
const {
isFirst,
data,
refClick,
} = props;
const barClick = () => {
const width = refClick();
console.log(`click width`, width);
setWidth(width);
};
const [width, setWidth] = useState(0);
useEffect(() => {
let width = refClick();
setWidth(width);
function reportWindowSize() {
console.log(`reszie`);
let width = refClick();
setWidth(width);
}
window.onresize = reportWindowSize;
}, [refClick]); return(
<>
<div className="funnel-chart-box" onClick={() => barClick()}>
<ChartTooltip data={data}>
<ChartBar
data={data}
isBase={isFirst}
base={width}
// base={barWidth}
/>
<ChartPercentage data={data} />
</ChartTooltip>
{/* <ChartBar
data={data}
isBase={isFirst}
base={width}
// base={barWidth}
/>
<ChartPercentage data={data} /> */}
</div>
</>
);
}; export default ChartBox;

Mutation Observer

https://javascript.ruanyifeng.com/dom/mutationobserver.html

https://developer.mozilla.org/zh-CN/docs/Web/API/MutationObserver


https://codepen.io/xgqfrms/pen/eYYRwRM

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


window resize & resize observer的更多相关文章

  1. 关于window的resize事件

    也许你也遇到过这样的问题,或者还没注意到有过这样的问题,如下代码,在窗口发生变化时,会进入死循环: var _funResize = function(){ console.log('resize.. ...

  2. 获取屏幕翻转:var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'

    var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',这段是为了获取移动端屏幕是否翻转(手机重力 ...

  3. autoHeight # 动态高度添加 用 window.addEventListener('resize', function () {

    动态高度添加 用 window.addEventListener('resize', function () { mounted () { this.init() window.addEventLis ...

  4. vue 中监听窗口发生变化,触发监听事件, window.onresize && window.addEventListener('resize',fn) ,window.onresize无效的处理方式

    // 开始这样写,不执行 window.onresize = function() { console.log('窗口发生变化') } // 改成window监听事件 window.addEventL ...

  5. 动态高度计算 height window.addEventListener('resize', () => {

    created() { window.addEventListener('resize', () => { }) },

  6. openstack instance resize Resize error: Unable to resize disk down

  7. JQuery 在$(window).load() 事件中 不运行 $(window).resize()

    本文转载至: http://stackoverflow.com/questions/2597152/jquery-window-resize-doesnt-work-on-load 原文标题   :J ...

  8. 解决Javascript中$(window).resize()多次执行(转)

    https://www.cnblogs.com/shuilangyizu/p/6816756.html 有些时候,我们需要在浏览器窗口发生变化的时候,动态的执行一些操作,比如做自适应页面时的适配.这个 ...

  9. 解决Javascript中$(window).resize()多次执行

    有些时候,我们需要在浏览器窗口发生变化的时候,动态的执行一些操作,比如做自适应页面时的适配.这个时候,我们需要在窗口拖动的时候去执行代码.但是有些时候,执行的操作比较复杂,我们只希望在窗口拖动完毕之后 ...

随机推荐

  1. 栈 堆 stack heap 堆内存 栈内存 内存分配中的堆和栈 掌握堆内存的权柄就是返回的指针 栈是面向线程的而堆是面向进程的。 new/delete and malloc/ free 指针与内存模型

    小结: 1.栈内存 为什么快? Due to this nature, the process of storing and retrieving data from the stack is ver ...

  2. 非关系型数据库(NOSQL)和关系型数据库(SQL)区别详解

    前言: 在我们的日常开发中,关系型数据库和非关系型数据库的使用已经是一个成熟的软件产品开发过程中必不可却的存储数据的工具了.那么用了这么久的关系数据库和非关系型数据库你们都知道他们之间的区别了吗?下面 ...

  3. Web渗透-SQLmap

    Web渗透-SQLmap 一.sqlmap简介 1.1 sqlmap 参数解析 二.sqlmap自动化注入 2.4 提权操作 示例步骤: 1.获得当前数据库 2.获得数据库表 3.获得表的字段 4.获 ...

  4. debian 屌丝日记

    好几年前,刚开始学习linux时,写的笔记,现在看来还挺有意思的,发出来 纪念下   1.安装debian系统,只安装最基本系统 不要桌面,不要print server,具体不会看网上图文并茂的 1) ...

  5. markdown 编辑器使用教程---字体、颜色、表格换行、链接等

    资源池: 绿色版markdown编辑器:点击这里 提取码:ftf9 1.标题 #一级标题 ##二级标题 ###三级标题 ####四级标题 #####五级标题 ######六级标题 一级标题 二级标题 ...

  6. charles(3)charles防止30分钟自动重启

    前言 Charles是收费软件,可以免费试用30天.试用期过后,未付费的用户仍然可以继续使用,但是每次使用时间不能超过30分钟,并且启动时将会有10秒种的延时. 此时,我们只需网上找一个注册码即可 解 ...

  7. 解析一下C++的异常处理

    ​ 作者:良知犹存 转载授权以及围观:欢迎添加微信:Allen-Iverson-me-LYN 总述     在程序运行过程中经常会碰到一些问题,例如数组下标越界,除数为零等,这些错误不过能被发现处理, ...

  8. Python爬虫入门教程:豆瓣Top电影爬取

        基本开发环境 Python 3.6 Pycharm 相关模块的使用 requests parsel csv 安装Python并添加到环境变量,pip安装需要的相关模块即可. 爬虫基本思路 一. ...

  9. [SCOI2009] [BZOJ1026] windy数

    windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数?\(1 \le A \le ...

  10. 【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}

    题意:求奇质数 P 的原根个数.若 x 是 P 的原根,那么 x^k (k=1~p-1) 模 P 为1~p-1,且互不相同. (3≤ P<65536) 解法:有费马小定理:若 p 是质数,x^( ...