How to use the imageryLayer.alpha by function(frameState, layer, x, y, level)

I’m trying to implementation the tiles of imageryLayer fade in/out when the zoom change(to make it switch smoothly).I found that alpha property might do that and it accepts either Number or function.
When i used

{ alpha: 1 }

or other number, it work fine. But the earth turns black when i try to use function like

alpha: function(frameState, layer, x, y, level) {
console.log(x, y, level)
return 1;

What did I do wrong? Or how can i to implementation what i want?

Hi @QianWu184,

Can you put together a sandcastle that demonstrates your issue? It will help to have a live code example so we can help you better. Thanks in advance!