如果在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; }} />
- );
- }
- }
-
相关阅读:
万丈高楼平地起——基于飞桨PaddleGAN与PaddleRS实现建筑物样本扩充工具
设计模式:UML类图
计算机基础内容——网络基础
goLang笔记+beego框架
Pytorch量化感知训练
IB经济与商业可以一起选吗?
2023-09-07力扣每日一题
postgresql:记录表膨胀引起的io问题的处理
音视频封装格式:AAC音频基础和ADTS打包方案详解
一个发誓不用Java的程序员,不得不在太空中调试Lisp
-
原文地址:https://blog.csdn.net/zz130428/article/details/128199226