我将制作一个非常小的Chrome 扩展程序,每 5 秒在页面上向下滚动一次,直到单击按钮。
我的问题是当按钮被点击时我可以得到事件。
popup.js
$("#stop").click(function() {
alert(1);
});
$("#start").click(function() {
setInterval(function(){
$("html, body").animate({ scrollTop: $(document).height() }, 1000);
}, 5000);
});
/*
$(window).load(function() {
setInterval(function(){
$("html, body").animate({ scrollTop: $(document).height() }, 1000);
}, 5000);
});
*/
html
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
min-width: 357px;
overflow-x: hidden;
}
input {
float: right;
}
</style>
<script src="jquery-latest.js"></script>
<script src="popup.js"></script>
</head>
<body>
Classname <input type="text" name="classname" id="classname"><br>
Interval: <input type="text" name="interval"><br>
<button type="button" id="start">Scroll Down</button>
<button type="button" id="stop" onclick="test()">Stop</button>
</body>
</html>
显现
{
"manifest_version": 2,
"name": "One-click Kittens",
"description": "This extension demonstrates a 'browser action' with kittens.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": ["tabs", "http://*/*", "background"],
"content_scripts": [ {
"matches": ["http://*/*"],
"js": [ "jquery-latest.js","popup.js" ],
"matches": [ "http://*/*", "https://*/*"],
"run_at": "document_end"
}]
}