How can I stop the spin? Something strange happens. Here is the code that doesn’t work:
<body>
<div id="spin">
</div>
<button type="submit" onclick="spin_stop();" id="stop">Stop</button>
<button type="submit" onclick="spin_start();" id="start">Start</button></p>
<script type="text/javascript">
var target = document.getElementById('spin');
function spin_stop() {
spinner.stop();
}
function spin_start() {
var spinner = new Spinner(opts).spin(target);
spinner.spin(target);
}
</script>
</body>
</html>
Since you are defining spinner in the function scope of spin_start(), the spinner object in spin_stop is undefined. If you declare spinner where you declare target, that variable will be accessible to both functions.