2017-09-29 61 views
0

我有在IE11的问题,该行jQuery是不承认的......:IE11 JS错误常量名=>功能

const applyHeights = (items, height) => { 

你有任何想法如何使它工作?这将是真棒!它在其他浏览器如chrome,safari,firefox等上都可以正常工作!

谢谢!

- 编辑 -

作为下面:

let maxHeight = Math.max(...heights); 

--all CODE -

setTimeout(function(){ 
setTimeout(function() { 
const applyHeights = function(items, height) { 
     const applyHeights = function(items, height) { 
const applyHeights = function(items, height) { 
     items.forEach(function(item) { 
    let back = item.querySelector('.back'), 
     front = item.querySelector('.front'); 

    back.style.height = height; 
    front.style.height = height; 
    item.style.height = height; 
}); 
} 

const getHeights =function (items, className) { 
return Array.from(items).map(function(item) { 
    return item.querySelector('.${className}').offsetHeight; 
}); 
} 

const initFlip = function(id) { 
let element = document.getElementById(id); 

if(!element) return; 

initHeights(element); 

window.onresize = function(event) { 
    resetHeights(element); 
    initHeights(element);   
} 
} 

const initHeights = function(element) { 
let items = element.querySelectorAll('article'), 
    backHeights = getHeights(items, 'back'), 
    frontHeights = getHeights(items, 'front'); 

let heights = backHeights.concat(frontHeights); 

var maxHeight = Math.max(...heights); 

applyHeights(items, '${maxHeight}px'); 
} 

const resetHeights = function(element) { 
let items = element.querySelectorAll('article'); 

applyHeights(items, 'auto'); 
} 
+0

这是_Javascript_,而不是jQuery。 – SLaks

+4

IE11不支持ES6。使用转译器。 – SLaks

+0

SLaks,谢谢,这是什么意思? – thibaultlgd

回答

0

(value)=>{}的语法被称为 '箭头函数'。它是ecmascript2015(ES6)的一个特性,是脚本语言规范。 Internet Explorer 11本身不支持ES6。 为了在IE11上运行ES6,你需要一个编译器,它可以编译es6到es5(IE11可以理解),这是babeljs最常用的编译器。 它与jquery无关。