IE8切片调用问题-Array.prototype.slice-'这'不是Javascript对象
IE8 slice call issue - Array.prototype.slice - 'this' is not a Javascript object
这是一个比以前问的问题更复杂的问题,尝试使用以前给出的响应,但它不起作用。
这是代码
(function () {
function init() {
var speed = 330,
easing = mina.backout;
[].slice.call(document.querySelectorAll('.grid > a')).forEach(function (el) {
var s = Snap(el.querySelector('svg')), path = s.select('path'),
pathConfig = {
from: path.attr('d'),
to: el.getAttribute('data-path-hover')
};
el.addEventListener('mouseenter', function () {
path.animate({ 'path': pathConfig.to }, speed, easing);
});
el.addEventListener('mouseleave', function () {
path.animate({ 'path': pathConfig.from }, speed, easing);
});
});
}
init();
})();
只要选择器('.grid > a'
)符合CSS2,这应该可以正常工作。因为querySelectorAll
只支持IE8中的css2选择器。
此外,你不需要调用slice方法,只需像这个一样直接使用for each
[].forEach.call(document.querySelectorAll('.grid > a'), function (el) {
var s = Snap(el.querySelector('svg')), path = s.select('path'),
pathConfig = {
from: path.attr('d'),
to: el.getAttribute('data-path-hover')
};
el.addEventListener('mouseenter', function () {
path.animate({ 'path': pathConfig.to }, speed, easing);
});
el.addEventListener('mouseleave', function () {
path.animate({ 'path': pathConfig.from }, speed, easing);
});
});
更新-[].forEach
与>=IE9 兼容
var nodeArray = [].slice.call(document.querySelectorAll('.grid > a'));
for (var i = 0; i < nodeArray.length; i++) {
var el = nodeArray[i];
var s = Snap(el.querySelector('svg')),
path = s.select('path'),
pathConfig = {
from: path.attr('d'),
to: el.getAttribute('data-path-hover')
};
el.addEventListener('mouseenter', function () {
path.animate({
'path': pathConfig.to
}, speed, easing);
});
el.addEventListener('mouseleave', function () {
path.animate({
'path': pathConfig.from
}, speed, easing);
});
}
相关文章:
- 微风得到的是实体而不是对象的集合
- 类型错误'未定义'不是对象(正在评估'navigator.connection.type'
- 保存id数组's而不是对象
- 返回 JavaScript 类值而不是对象引用
- TypeError:undefined不是对象(正在评估'newWindow.focus')
- 为什么Angularjs服务返回的是字符数组而不是对象数组
- global.getElementById('..')为null或不是对象
- IE8错误:为null或不是对象,但仍然可以跟踪/控制台注销
- AngularJS错误:请求的键的值不是对象.keys@[本地代码]
- ui.selectmenu投掷'this.newelement.0'为null或不是对象
- UI-Select2 绑定到对象而不是对象的属性
- 类型错误:'null'不是对象(正在评估'响应.productType')
- Karma+PhantomJS TypeError:undefined不是对象(正在评估scope.jjackpot)
- Node.appendChild的参数1不是对象
- html5拖动&drop-TypeError:Node.appendChild的参数1不是对象
- 我的代码给了我一条错误消息:GetElementById()为null或不是对象
- 控制台返回[Object-Object]而不是对象成员
- AngularJS Jasmine测试:类型错误:'未定义'不是对象
- Javascript'type[..][..]'为null或不是对象IE8错误
- TypeError:undefined不是对象(正在评估'this.props')-React Nati