在react项目中实现此功能可借助 react-rnd 库,文档地址:https://github.com/bokuweb/react-rnd#Screenshot 。下面是实例运用:

  

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import assign from 'object-assign'
import classNames from 'classnames'
import _ from 'lodash'
import { Rnd } from 'react-rnd' import './index.less' class ScreenShareCapture extends Component {
static propTypes = {
style: PropTypes.object,
} static defaultProps = {
style: {},
} state = {
x: 0,
y: 0,
width: 500,
height: 281.25,
} componentDidMount() {
} componentWillUnmount() {
} updateRndElemLastSizePos = () => {
this.rndElemLastSizePos = {
x: this.state.x,
y: this.state.y,
width: this.state.width,
height: this.state.height,
}
} calculateRndElemSizePos = (dir, ref, sizeDelta, position) => {
const sizePos = _.clone(this.rndElemLastSizePos)
const heightWidthRatio = 0.5625
sizePos.x = position.x
sizePos.y = position.y
sizePos.width = ref.offsetWidth
sizePos.height = ref.offsetWidth * heightWidthRatio this.setState(sizePos)
return sizePos
} handleDragStart = () => {
this.updateRndElemLastSizePos()
} handleDrag = (e, data) => {
this.setState({
x: data.x,
y: data.y,
})
} handleDragStop = (e, data) => {
this.setState({
x: data.x,
y: data.y,
})
} handleResizeStart = () => {
this.updateRndElemLastSizePos()
} handleResize = (e, dir, ref, delta, position) => {
console.log('beibei handleresize', e, dir, ref, delta, position)
this.calculateRndElemSizePos(dir, ref, delta, position)
} rndElemLastSizePos rnd render() {
const wrapStyles = assign({}, this.props.style)
return (
<Rnd
style={wrapStyles}
bounds=".teacher-layout-component-wrap"
dragHandleClassName="screen-share-bottom-content-wrap"
enableResizing={{
top: false,
right: false,
bottom: false,
left: false,
topRight: true,
bottomRight: true,
bottomLeft: true,
topLeft: true,
}}
position={{
x: this.state.x,
y: this.state.y,
}}
size={{
width: this.state.width,
height: this.state.height,
}}
lockAspectRatio={16 / 9}
maxWidth="100%"
maxHeight="100%"
minWidth={400}
minHeight={225}
onDragStart={this.handleDragStart}
onDrag={this.handleDrag}
onDragStop={this.handleDragStop}
onResizeStart={this.handleResizeStart}
onResize={this.handleResize}
onResizeStop={_.noop}
ref={(r) => { this.rnd = r }}
>
<div className="screen-share-capture-component-wrap">
<div className="screen-share-main-content-wrap">
<span className="start-screen-share-button">开始屏幕共享</span>
</div>
<div className="screen-share-bottom-content-wrap">
<div className="screen-share-bottom-left">
<i
className="preview-icon"
/>
<span className="preview-text">预览</span>
</div>
<div className="screen-share-bottom-right">
<i
className={classNames({
'device-icon': true,
'camera-icon': true,
active: false,
})}
/>
<i
className={classNames({
'device-icon': true,
'mic-icon': true,
active: false,
})}
/>
<i
className={classNames({
'device-icon': true,
'speaker-icon': true,
active: false,
})}
/>
<i
className={classNames({
'device-icon': true,
'wifi-icon': true,
active: false,
})}
/>
{/*<i*/}
{/*className={classNames({*/}
{/*'device-icon': true,*/}
{/*'restart-icon': true,*/}
{/*active: false,*/}
{/*})}*/}
{/*/>*/}
<i
className={classNames({
'device-icon': true,
'exit-icon': true,
active: false,
})}
/>
</div>
</div>
</div>
</Rnd>
)
}
} export default ScreenShareCapture

  下面是css样式:

  

.screen-share-capture-component-wrap{
box-sizing: border-box;
width: 100%;
height: 100%;
position: relative;
//top:;
//left:;
//width: 100%;
//height: 100%;
//display: flex;
//flex-direction: column;
//align-items: center;
//justify-content: center;
//background-color: red; .screen-share-main-content-wrap{
box-sizing: border-box;
width: 100%;
height: 100%;
border-radius: 2px;
border: solid 2px #ff4343;
background-color: #ffffff;
display: flex;
justify-content: center;
align-items: center; .start-screen-share-button{
display: inline-block;
width: 120px;
height: 36px;
line-height: 36px;
text-align: center;
border-radius: 2px;
background-color: #ff4343;
color: #ffffff;
font-size: 14px;
opacity: 0.8;
cursor: pointer;
}
} .screen-share-bottom-content-wrap{
width: 100%;
height: 36px;
border-radius: 2px;
background-color: #5d6674;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
position: absolute;
bottom: -36px;
left:; .screen-share-bottom-left{
width: 72px;
height: 32px;
border-radius: 2px;
border: solid 1px #ffffff;
background-color: #5d6674;
margin: 3px;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
cursor: pointer; .preview-icon{
width: 24px;
height: 24px;
outline: none;
cursor: pointer;
background: url('~ROOT/shared/assets/image/vn-screen-preview-42-42.png') no-repeat center;
background-size: 16px 16px;
} .preview-text{
color: #ffffff;
font-size: 14px;
}
} .screen-share-bottom-right{
display: flex;
flex-direction: row;
align-items: center; .device-icon {
width: 24px;
height: 24px;
outline: none;
cursor: pointer;
margin-right: 11px; &:nth-last-child(2){
margin-right: 38px;
} } .camera-icon {
background: url('~ROOT/shared/assets/image/vn-screen-camera-off-66-66.png') no-repeat center;
background-size: 22px 22px;
} .mic-icon {
background: url('~ROOT/shared/assets/image/vn-screen-voice-on-54-72.png') no-repeat center;
background-size: 18px 24px;
} .speaker-icon {
background: url('~ROOT/shared/assets/image/vn-screen-speaker-60-66.png') no-repeat center;
background-size: 20px 22px;
} .wifi-icon {
background: url('~ROOT/shared/assets/image/vn-screen-wifi-72-57.png') no-repeat center;
background-size: 24px 19px;
} .restart-icon{
background: url('~ROOT/shared/assets/image/vn-screen-restart-60-60.png') no-repeat center;
background-size: 19px 19px;
} .exit-icon{
background: url('~ROOT/shared/assets/image/vn-screen-exit-60-60.png') no-repeat center;
background-size: 19px 19px;
} } }
}

react项目中实现元素的拖动和缩放实例的更多相关文章

  1. 如何在非 React 项目中使用 Redux

    本文作者:胡子大哈 原文链接:https://scriptoj.com/topic/178/如何在非-react-项目中使用-redux 转载请注明出处,保留原文链接和作者信息. 目录 1.前言 2. ...

  2. react项目中实现搜索关键字呈现高亮状态(一)

    最近有个需求,在一个react项目中,实现搜索关键字呈现高亮状态.这个在普通的html文件中还好操作些,在react项目中有点懵逼了,因为react项目中很少操作dom,有点无从下手.但最后还是实现了 ...

  3. 如何优雅地在React项目中使用Redux

    前言 或许你当前的项目还没有到应用Redux的程度,但提前了解一下也没有坏处,本文不会安利大家使用Redux 概念 首先我们会用到哪些框架和工具呢? React UI框架 Redux 状态管理工具,与 ...

  4. React项目中实现右键自定义菜单

    最近在react项目中需要实现一个,右键自定义菜单功能.找了找发现纯react项目里没有什么工具可以实现这样的功能,所以在网上搜了搜相关资料.下面我会附上完整的组件代码. (注:以下代码非本人原创,具 ...

  5. React项目中使用Mobx状态管理(二)

    并上一节使用的是普通的数据状态管理,不过官方推荐使用装饰器模式,而在默认的react项目中是不支持装饰器的,需要手动启用. 官方参考 一.添加配置 官方提供了四种方法, 方法一.使用TypeScrip ...

  6. 在react项目中使用ECharts

    这里我们要在自己搭建的react项目中使用ECharts,我们可以在ECharts官网上看到有一种方式是在 webpack 中使用 ECharts,我们需要的就是这种方法. 我们在使用ECharts之 ...

  7. 优雅的在React项目中使用Redux

    概念 首先我们会用到哪些框架和工具呢? React UI框架 Redux 状态管理工具,与React没有任何关系,其他UI框架也可以使用Redux react-redux React插件,作用:方便在 ...

  8. 深入浅出TypeScript(5)- 在React项目中使用TypeScript

    前言 在第二小节中,我们讨论了利用TypeScript创建Web项目的实现,在本下节,我们讨论一下如何结合React创建一个具备TypeScript类型的应用项目. 准备 Webpack配置在第二小节 ...

  9. redux在react项目中的应用

    今天想跟大家分享一下redux在react项目中的简单使用 1 1.redux使用相关的安装 yarn add redux yarn add react-redux(连接react和redux) 2. ...

随机推荐

  1. Centos7 HyperLedger Fabric 1.4 生产环境部署

    Kafka生产环境部署案例采用三个排序(orderer)服务.四个kafka.三个zookeeper和四个节点(peer)组成,共准备八台服务器,每台服务器对应的服务如下所示: kafka案例网络拓扑 ...

  2. Nginx与PHP-FPM运行原理详解

    目录 1. 代理与反向代理 1. 正向代理:访问google.com 2. 反向代理:通过反向代理实现负载均衡 2. 初识Nginx与PHP-FPM 1. Nginx是什么 2. CGI与FastCG ...

  3. linux安装软件时提示找不到镜像的问题:Couldn't resolve host 'mirrorlist.centos.org'

    问题:[root@cddserver2 ~]# yum -y install gcc-*Loaded plugins: fastestmirror, prestoCould not retrieve ...

  4. python类与对象-如何派生内置不可变类型并修其改实例化行为

    如何派生内置不可变类型并修其改实例化行为 问题举例 自定义一种新类型的元组,对传入的可迭代对象,我们只保留 其中int类型且值大于0的元素,例如 IntTuple([1, -1, 'abc', 6, ...

  5. EF:分页查询 + 条件查询 + 排序

    /// <summary> /// linq扩展类---zxh /// </summary> /// <typeparam name="T">& ...

  6. Python学习笔记(Ⅰ)——Python程序结构与基础语法

    作为微软的粉丝,最后终于向Python低头了,拖了两三个月终于下定决心学习Python了.不过由于之前受到C/C#等语言影响的思维定式,前期有些东西理解起来还是很费了些功夫的. 零.先抄书: 1.Py ...

  7. Oracle exp和expdp对数据进行备份

    以下给出两个示例,详细内容需要查阅手册: exp system OWNER=ZLTX FILE=ZLTX20190123.DMP expdp system DUMPFILE=ZLTX20190123. ...

  8. sql server中的开窗函数over、视图、事物

    一.开窗函数over的作用有两个: 1.排序order by,row_number,翻页 2.划区partition by,结合聚合函数针对某部分数据进行汇总 翻页的sql server 语句: an ...

  9. P1772 [ZJOI2006]物流运输

    题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪. ...

  10. Mysql 聚合函数返回NULL

    [1]聚合函数返回NULL 当where条件不满足时,聚合函数sum().avg()的返回值为NULL. (1)源数据表 (2)如下SQL语句 SELECT sClass, COUNT(*) AS t ...