Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Не работает всплывающее окно (https://javascript.ru/forum/jquery/9968-ne-rabotaet-vsplyvayushhee-okno.html)

exec 13.06.2010 12:50

Не работает всплывающее окно
 
Вот код:

function jWnd(sets) {
	var header = sets.header ? '<div style="position: relative; background: #555; border-bottom: 3px solid orange; width: ' + sets.w + 'px; height: 20px;">' + sets.header + '</div>': '';
	var content = '<div style="position: relative; background: #555; width: ' + sets.w + 'px; height: ' + sets.h + '">' + sets.content + '</div>';
	var x = $('<div style="position: fixed; opacity: 0">' + header + content + '</div>');
	x.appendTo($('body')).css({
		top: ($(document).height() - $(x).height()) / 2,
		left: ($(document).width() - $(x).width()) / 2
	}).animate({
		opacity: 1
	},
	1000);
};


При вызове jWnd из скрипта всё работает, а если попытаться сделать это в onclick ссылки — ничего нет. Где ошибка?

рони 14.06.2010 05:54

var content = '<div style="position: relative; background: #555; width: ' + sets.w + 'px; height: ' + sets.h + 'px ">' ---а сам код рабочий
можно ещё самоудаление добавить по клику если оно конечно надо)))
<script language="JavaScript" src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function jWnd(sets) {
   var header = sets.header ? '<div style="position: relative; background: #555; border-bottom: 3px solid orange; width: ' + sets.w + 'px; height: 20px;">' + sets.header + '</div>': '';
   var content = '<div style="position: relative; background: #555; width: ' + sets.w + 'px; height: ' + sets.h + 'px">' + sets.content + '</div>';
   var x = $('<div style="position: fixed; opacity: 0">' + header + content + '</div>');
	x.appendTo($('body')).css({
		top: ($(document).height() - $(x).height()) / 2,
		left: ($(document).width() - $(x).width()) / 2
	}).animate({
		opacity: 1
	},
	1000).click(function () {
      $(this).remove()} )
};
/*]]>*/
</script>
<a href="#" onclick='jWnd({"header":"Заголовок","content":"Содержание","w":200,"h":50})'>пуск</a>

exec 14.06.2010 08:40

Спасибо за то, что дали наводку. Я просто делал так: открывал сайт, нажимал Ctrl+U и начинал прямо в исходнике писать скрипт и потом смотреть результат. Ничего не работало. А вот если запускать на пустой странице, то всё работает.


Часовой пояс GMT +3, время: 11:02.