x
1
<style>
2
#image {
3
width: 375px;
4
height: 200px;
5
border: 1px solid black;
6
background-color: #dededf;
7
object-fit: none;
8
}
9
</style>
10
11
<p>检查开发人员工具以查看控制台中的日志,并检查图像上的样式属性。</p>
12
<img id="image" src="https://u.mifengjc.com/images/logo.png" alt="Logo"/>
13
14
<script>
15
let replacedEl = document.getElementById( 'image' );
16
let position = new CSSPositionValue( CSS.px(35), CSS.px(40) );
17
18
replacedEl.attributeStyleMap.set( 'object-position', position );
19
console.log( position.x.value, position.y.value );
20
console.log( replacedEl.computedStyleMap().get('object-position') );
21
</script>
22