udpate js code to handle scroll event