如果在react中这么样写:
- // Your code:
- "something" />
在react 15中将被渲染成:
- // React 15 output:
在react 16及之后的版本中将被渲染成:
- // React 16 output:
- "something" />
但这个会有限制,如果自定义的属性不是 string, number 或者 object,该属性依然会被忽略。
所以目前可以这样添加 webkit-playsinline 属性:
- <source src="https://media.w3.org/2010/05/sintel/trailer.mp4" type="video/mp4"/>
另外,还可以通过 setAttribute 进行设置,比如:
- import * as React from 'react';
- import { Component } from 'react';
-
- export class VideoComponent extends Component {
- videoContainer: HTMLDivElement;
- componentDidMount() {
- const video = document.createElement('video');
- video.autoplay = true;
- video.loop = true;
- video.muted = true; // fixes autoplay in chrome
- video.setAttribute('playsinline', 'true'); // fixes autoplay in webkit (ie. mobile safari)
-
- const source = document.createElement('source');
- source.src = '/path/to/your/video.mp4';
- source.type = 'video/mp4';
- video.appendChild(source);
-
- this.videoContainer.appendChild(video);
- }
- render() {
- return (
- <div ref={(ref) => { this.videoContainer = ref; }} />
- );
- }
- }
-
相关阅读:
如何使用git-credentials来管理git账号
IDEA自带的HTTP Client 接口调试工具
ABP - 初识 ABP
“Ubuntu终端闪退”的解决方法
java中stream常用api介绍
Kafka消息分区&producer拦截器&无消息丢失(八)
Deformable Convolution 可变形卷积
eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑
基于Python的旅游景点推荐系统设计与实现(源码+数据库+讲解)
webpack5基于React+Antd搭建开发和生产环境
-
原文地址:https://blog.csdn.net/zz130428/article/details/128199226