optimize the effect when resize the window.