window resize & resize observer
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的更多相关文章
- 关于window的resize事件
也许你也遇到过这样的问题,或者还没注意到有过这样的问题,如下代码,在窗口发生变化时,会进入死循环: var _funResize = function(){ console.log('resize.. ...
- 获取屏幕翻转:var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'
var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',这段是为了获取移动端屏幕是否翻转(手机重力 ...
- autoHeight # 动态高度添加 用 window.addEventListener('resize', function () {
动态高度添加 用 window.addEventListener('resize', function () { mounted () { this.init() window.addEventLis ...
- vue 中监听窗口发生变化,触发监听事件, window.onresize && window.addEventListener('resize',fn) ,window.onresize无效的处理方式
// 开始这样写,不执行 window.onresize = function() { console.log('窗口发生变化') } // 改成window监听事件 window.addEventL ...
- 动态高度计算 height window.addEventListener('resize', () => {
created() { window.addEventListener('resize', () => { }) },
- openstack instance resize Resize error: Unable to resize disk down
- JQuery 在$(window).load() 事件中 不运行 $(window).resize()
本文转载至: http://stackoverflow.com/questions/2597152/jquery-window-resize-doesnt-work-on-load 原文标题 :J ...
- 解决Javascript中$(window).resize()多次执行(转)
https://www.cnblogs.com/shuilangyizu/p/6816756.html 有些时候,我们需要在浏览器窗口发生变化的时候,动态的执行一些操作,比如做自适应页面时的适配.这个 ...
- 解决Javascript中$(window).resize()多次执行
有些时候,我们需要在浏览器窗口发生变化的时候,动态的执行一些操作,比如做自适应页面时的适配.这个时候,我们需要在窗口拖动的时候去执行代码.但是有些时候,执行的操作比较复杂,我们只希望在窗口拖动完毕之后 ...
随机推荐
- 【Source Insight】查找功能 Lookup References 详解
1.Options Case Sensitive //区分大小写 Whole Words Only //全字匹配查找 Skip Inactive Code //跳过无效代码查找 Skip Commen ...
- 小麦苗数据库巡检脚本,支持Oracle、MySQL、SQL Server和PG等数据库
目录 一.巡检脚本简介 二.巡检脚本特点 三.巡检结果展示 1.Oracle数据库 2.MySQL数据库 3.SQL Server数据库 4.PG数据库 5.OS信息 四.脚本运行方式 1.Oracl ...
- 二进制GCD
目录 写在前面 具体实现: Code 写在前面 全程抄书 想要进一步提高求 \(\gcd\) 的效率,可以通过不断去除因子 \(2\) 来降低常数,这就是"二进制 \(\gcd\) &quo ...
- HDU1814和平委员会
题目大意: 有n对的人,编号从1-2*n,m对的人之间互相不喜欢,每对人中必徐选1个人加入和平委员会,求字典序最小的解 -------------------------------- 2-SAT问题 ...
- java.util.List.subList使用注意
List<E> subList(int fromIndex, int toIndex); 它返回原来list的从[fromIndex, toIndex)之间这一部分的视图,之所以说是视图, ...
- MapReduce编程练习(四),统计多个输入文件学生的平均成绩,
问题描述: 在输入文件中,有多个,其中每个输入文件代表一个学生的各科成绩,其中每行的数据形式为<科目,成绩>,你需要将每个文件中的每科目的成绩进行统计,然后求平均值. 输入文件格式: 这里 ...
- C++ 标准模板库(STL):map
目录 4. map 4.1 map的定义 4.2 map容器内元素的访问 4.3 map常用函数实例解析 4.4 map的常见用途 4. map map翻译为映射,也是常用的STL容器. 在定义数组时 ...
- 深度学习论文翻译解析(十九):Searching for MobileNetV3
论文标题:Searching for MobileNetV3 论文作者:Andrew Howard, Mark Sandler, Grace Chu, Liang-Chieh Chen, Bo Che ...
- 500行SQL快速实现UCF
写在前面话 UCF通常是User-base Collaborative Filter的简写;大体的算法思路是根据用户行为计算相似群体(邻居),为用户推荐其邻居喜好的内容:感觉是不是很简单.那废话不多说 ...
- zookper投票机制
前提:已经搭建好zookper集群 1.先开启编号为01的服务器 2.开启编号为02的服务器,状态为leader,编号为01的变成follower 3.开启编号为03的服务器,状态为follower ...