[英]getPropertyValue doesn't wok in IE9?
I want to use transition
and transform
to make a slider. 我想使用
transition
和transform
来制作滑块。 I use the getPropertyValue
to check the current slide. 我使用
getPropertyValue
检查当前幻灯片。 It works fine in Chrome, but in the IE9 it shows an error: TypeError: Cannot read property '0' of null
(I marked the line with **) 它在Chrome中工作正常,但在IE9中显示错误:
TypeError: Cannot read property '0' of null
(我用**标记了该行)
the Javascript
code: Javascript
代码:
var slider = container.querySelector("ul");
function getCurrSliderIndex() {
var text = slider.style.getPropertyValue("transform");
console.log(text);
var pattern = /[0-9]+/;
**var match = pattern.exec(text)[0];**
var intValue = parseInt(match) / width - 1;
return intValue;
}
the HTML
code: HTML
代码:
<ul id="primary-slider" class=" iuiSlider fix" style="width: 3794px; height: 271px; transform: translateX(-1084px);">
<li>some content</li>
<li>some content</li>
<li>some content</li>
...
</ul>
The problem here is not really the getPropertyValue()
function, which is supported in IE9+. 此处的问题实际上不是IE9 +支持的
getPropertyValue()
函数。
But CSS properties like transform
need vendor prefixes to work across browsers. 但是,诸如
transform
类的CSS属性需要供应商前缀才能跨浏览器工作。 To make it easier, you could create functions that handle them so you don't have to: 为了简化操作,您可以创建处理它们的函数,因此您不必:
/* Declare these functions to handle the prefixes */ Object.prototype.setPrefixedProperty = function(prop, value){ this.setProperty(prop, value); this.setProperty('-moz-' + prop, value); this.setProperty('-webkit-' + prop, value); this.setProperty('-ms-' + prop, value); this.setProperty('-o-' + prop, value); }; Object.prototype.getPrefixedProperty = function(prop){ return this.getPropertyValue(prop) || this.getPropertyValue('-moz-' + prop) || this.getPropertyValue('-webkit-' + prop) || this.getPropertyValue('-ms-' + prop) || this.getPropertyValue('-o-' + prop); }; /* Use them like so: */ var slider = document.querySelector('div'); slider.style.setPrefixedProperty('transform', 'translateX(-1084px)'); var text = slider.style.getPrefixedProperty('transform'); alert(text);
<p>This demo should alert "translateX(-1084px)".</p> <div></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.