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. 腾讯libco协程原理

    https://blog.csdn.net/GreyBtfly/article/details/83688420 堆栈 https://blog.csdn.net/lqt641/article/det ...

  2. Atlas 2.1.0 实践(4)—— 权限控制

    Atlas的权限控制非常的丰富,本文将进行其支持的各种权限控制的介绍. 在atlas-application.properties配置文件中,可以设置不同权限的开关. atlas.authentica ...

  3. Jenkins免密码登录

    Jenkins免密码登录 相关内容原文地址: 简书:海边的卡夫卡丶:Jenkins免密码登录 昨天惊现一个神奇的问题,Jenkins无法登录,无论是初始化的账号密码,还是admin用户,都登录不进去了 ...

  4. Java面试(解答题一)

    1.简述下列问题 List,set,map的区别 解答:List,Set都是继承自Collection接口,Map则不是: List特点:元素有放入顺序,元素可重复 ,Set特点:元素无放入顺序,元素 ...

  5. Prometheus 初探和配置(安装测试)

    本文大纲: • Prometheus 官⽹下载• Prometheus 开始安装• Prometheus 启动运⾏• Prometheus 基本配置⽂件讲解• 安装第⼀个exporter => ...

  6. java调用shell脚本执行操作

    //定时清空 日志 String shellString = "sh /home/jyapp/delete_log.sh"; Process process = Runtime.g ...

  7. 13.Linux文件存储系统

    1.Linux 系统中的文件存储结构 Linux系统中常见的目录名称以及相应内容 2.系统内核中的udev 设备管理器会自动把硬件名称规范起来,目的是让用户通过设备文件的名字可以猜出设备大致的属性以及 ...

  8. TCP/IP__Cisco的3层分层模型

    1. Cisco的层次模型:3个层次和它们的典型功能 核心层:骨干 分配层:路由 接入层:交换 核心层 1. 核心层就是网络的核心.它位于顶层,负责可靠而迅速地传输大量的数据流.网络核心层的唯一意图是 ...

  9. java中的四种内部类使用(1)

    内部类 (一) 概述 把类定义在另一个类的内部,该类就被称为内部类. 举例:把类Inner定义在类Outer中,类Inner就被称为内部类. class Outer { class Inner { } ...

  10. Web APP和原生 APP的不同

    我们现在手机中的APP,大部分都是混合APP,也就是既用到了原生APP的基础,又用到了Web APP的基础,混合的比例从0%到100%之间不等.更好的了解APP的类型,有助于我们学则合适的测试策略.今 ...