Also the code has to be called when the slider is displayed – that depends on the ‘display’ event for the slider control, which is different for every slider.
You could also try the CSS workaround of positioning the hidden element off-screen.
Unfortunately, there’s no general answer. It depends on what type of plugin/control you’re using for the slider.
Here’s a link to the jQuery page explaining the same thing for their tabs control:
There are millions of hits about this problem on Google. Maybe someone has already found a a solution for that particular slider?