@Vadim1899

Как лучше сократить код?

Разбираюсь в javasctipt. Появилась необходимость установить на сайт "уведомления".

Взял код:
(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>This is just a simple notice. Everything is in order and this is a <a href="#">simple link</a>.</p>',
							layout : 'growl',
							effect : 'scale',
							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;
				} );
			})();


но код уведомление появляется только тогда, когда был клик по кнопке id=notification-trigger. Как лучше почистить код, чтобы окошко появлялось сразу при открытии страницы без всяких кнопок?
  • Вопрос задан
  • 105 просмотров
Решения вопроса 1
AlexMaxTM
@AlexMaxTM
Попробуйте так:
var notification = new NotificationFx({
              message : '<p>This is just a simple notice. Everything is in order and this is a <a href="#">simple link</a>.</p>',
              layout : 'growl',
              effect : 'scale',
              type : 'notice', // notice, warning, error or success
            });

notification.show();

Но можно сократить и до такого кода:
alert('This is just a simple notice. Everything is in order and this is a simple link')
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы