Javascript 将按钮活动脚本更改为onLoad效果
我有一个简单的代码可以显示一个通知框在左上角的网页时,点击特定的按钮 我需要的代码可以显示在网页的时刻通知框是完全准备和加载,在同一个地方,同一个计时器Javascript 将按钮活动脚本更改为onLoad效果,javascript,jquery,html,Javascript,Jquery,Html,我有一个简单的代码可以显示一个通知框在左上角的网页时,点击特定的按钮 我需要的代码可以显示在网页的时刻通知框是完全准备和加载,在同一个地方,同一个计时器 <!DOCTYPE html> <html lang="en" class="no-js"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="http://fonts.googleapis.com/css?family=Raleway:400,300,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/ns-default.css" />
<link rel="stylesheet" type="text/css" href="css/ns-style-growl.css" />
<script src="js/modernizr.custom.js"></script>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="color-9">
<div class="container">
<!-- Top Navigation -->
<div class="main clearfix">
<div class="column">
<button id="notification-trigger" class="progress-button">
<span class="content">Show Notification</span>
<span class="progress"></span>
</button>
</div>
</div>
<!-- Related demos --></div><!-- /container -->
<script src="js/classie.js"></script>
<script src="js/notificationFx.js"></script>
<script>
(function() {
var bttn = document.getElementById( 'notification-trigger' );
// make sure..
bttn.disabled = false;
bttn.addEventListener( 'click', function() {
// simulate loading (for demo purposes only)
classie.add( bttn, 'active' );
setTimeout( function() {
classie.remove( bttn, 'active' );
// create the notification
var notification = new NotificationFx({
message : '<p>Hello there! I\'m a classic notification but I have some elastic jelliness thanks to <a href="http://bouncejs.com/">bounce.js</a>. </p>',
layout : 'growl',
effect : 'jelly',
type : 'notice', // notice, warning, error or success
onClose : function() {
bttn.disabled = false;
}
});
// show the notification
notification.show();
}, 1200 );
// disable the button (for demo purposes only)
this.disabled = true;
} );
})();
</script>
显示通知
(功能(){
var bttn=document.getElementById('notification trigger');
//一定要。。
bttn.disabled=false;
bttn.addEventListener('click',function(){
//模拟加载(仅用于演示目的)
类别添加(bttn,“活动”);
setTimeout(函数(){
类别移除(bttn,“活动”);
//创建通知
var通知=新通知fx({
信息:“您好!我是一个典型的通知,但我有一些弹性果冻感谢。”,
布局:“咆哮”,
效果:“果冻”,
键入:“通知”,//通知、警告、错误或成功
onClose:function(){
bttn.disabled=false;
}
});
//显示通知
notification.show();
}, 1200 );
//禁用按钮(仅用于演示目的)
this.disabled=true;
} );
})();
如果有人能帮我修改代码,那就要提前多谢了。:) 只需单独声明click handler函数,然后您就可以在绑定它之后调用它,而无需触发click事件,
bttn.click()
就可以了
// Declare handler:
var clickHandler = function (event) {
// Your onclick function
};
bttn.addEventListener( 'click', clickHandler); // Bind handler
clickHandler(); // Fire it immediately
谢谢你的帮助
我已经编辑并找到了一种方法,最后一个块在这里编辑:
(function() {
var bttn = document.getElementById( 'notification-trigger' );
// make sure..
bttn.disabled = false;
addEventListener('load',function() {
// create the notification
var notification = new NotificationFx({
message : '<p>Hello there! I\'m a classic notification but I have some elastic jelliness thanks to <a href="http://bouncejs.com/">bounce.js</a>. </p>',
layout : 'growl',
effect : 'jelly',
type : 'notice', // notice, warning, error or success
onClose : function() {
bttn.disabled = false;
}
});
// show the notification
notification.show();
}, 1200 );
// disable the button (for demo purposes only)
this.disabled = true;
})();
(函数(){
var bttn=document.getElementById('notification trigger');
//一定要。。
bttn.disabled=false;
addEventListener('load',function(){
//创建通知
var通知=新通知fx({
信息:“您好!我是一个典型的通知,但我有一些弹性果冻感谢。”,
布局:“咆哮”,
效果:“果冻”,
键入:“通知”,//通知、警告、错误或成功
onClose:function(){
bttn.disabled=false;
}
});
//显示通知
notification.show();
}, 1200 );
//禁用按钮(仅用于演示目的)
this.disabled=true;
})();
谢谢你的帮助:)
现在工作正常。如果您不介意使用jQuery,可以使用
$(document).ready()
。在document.ready
(仍在其中)的底部添加:bttn.click()代码>--它将在页面加载时运行。是的,我很愚蠢,我已经编辑了代码并且工作得很好!非常感谢:)