Задача: При клике по ссылки, страница сначала плавно исчезает, а потом происходит переход. Исходные данные: //Код jquery //Собираем все ссылки (анкоры) на страцице $('a').click(function(){ //Плавное погасание всей страницы $('#all').animate({opacity: 0},2000); //Переход на следюующую страницу. (проблема в этом месте, т.е. код выполняется параллельно и при нажатии на ссылку сразу возвращатеся return , вопрос: как сделать переход после того как страница погаснет? `` return true; }); |
2 answers
Use callback complete which can be passed in the options of the animate function, also to prevent the default action in this case from the links, use preventDefault. Example ( JSFiddle ) :
$(function(){ $('a').click(function(e){ var context = $(this); $('body').animate({opacity: 0}, { speed : 2000, complete : function(){ var domain = location.hostname, href = context.prop('href'); if (href.indexOf("http://") > -1) { document.location.href = href; } else { document.location.href = domain + href; } } }); e.preventDefault(); }); }); - the page goes out, but the transition does not occur. What can be wrong? - MaXiM3006
- Perhaps due to the fact that the transition within the site - MaXiM3006
- Give an example link - Kison
- <a href="/contacts.html"> Contacts </a> - MaXiM3006
- Watch the update - Kison
|