Skip to content

Instantly share code, notes, and snippets.

@nansenat16
Created July 19, 2013 04:06
Show Gist options
  • Save nansenat16/6035091 to your computer and use it in GitHub Desktop.
Save nansenat16/6035091 to your computer and use it in GitHub Desktop.
示範更換分頁停止倒數
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
var count=0;
$(window).blur(function(){
console.log('out');
$('#msg').data('where','out');
});
$(window).focus(function(){
console.log('in');
$('#msg').data('where','in');
});
setInterval(function(){
if($('#msg').data('where')=='in'){
$('#msg').text(count);
count=count+1;
}
},1000);
// you can stop blur on develop console
// $(window).off('blur')
</script>
</head>
<body>
<div id="msg" data-where="in" style="width:100px;height:100px;background-color:green;color:red;font-size:40pt;"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment