Плавная смена позиции Div без position: relative
Вообщем задача такая: есть некий див блок при нажатии на клавишу в нем он сдвигается влево (планирую делать появление другого дива в центре). Нельзя использовать в стилях "position: relative" ибо мне нужно чтобы блок сначала стоял в центре а потом сдвигался влево:
Реализовать я это смог, но как добавить плавности ? я так понимаю с помощью animate - но как именно не знаю. Вот код страницы и цсс: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Тест-тест</title> <script type="text/javascript" src="jquery.js"></script> <link href="styles.css" rel="stylesheet" type="text/css" /> </head> <script type="text/javascript"> $(document).ready(function(){ $(".button").click(function(){ $(".menu").toggleClass("active") return false }); }); </script> <body> <div class="box"> <div class="menu"> <a href="#" class="button">Change position </a> </div> </div> </body> </html> body {background-color:#999; margin: 0px; padding: 0px;} .box { margin-left: auto; margin-right: auto; margin-top: 100px; width: 600px;} .button {color:#333; text-decoration:none; margin-top: 15px; margin-left: 15px;} .menu { width: 150px; height: 200px; margin-left: auto; margin-right: auto; background-color: #FFF;} .active {margin-left: 0;} Ели можно также подскажите как выстроить блок в одну строку не юзая при этом в первом блоке(.menu) clear:both, т.к. там маргины ... Спасибо |
ОБНОВЛЕНО, ИЗМЕНЕНИЯ
не нашел как изменить первый пост
ситуация изменилась: я попыхтел и сделал появление блока с контентом, + написал проверку на его наличие вопрос остался прежним как добавить плавности движения в бок menu (за 1 секунду) + как отсрочить появление блока с контентом на 1 секунду: т.е. сдвинулось меню в бок (за 1 сек) и появился блок с контентом (планируется сделать Ajax подгрузку в блок с контентом информации в зависимости от выбраного раздела в меню). Что имеем сейчас: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Тест-тест</title> <script type="text/javascript" src="jquery.js"></script> <link href="styles.css" rel="stylesheet" type="text/css" /> </head> <script type="text/javascript"> $(document).ready(function(){ $(".button").click(function(){ if( $(".active").size() > 0 ) { // усли .active присутствует // ничего не проиходит } else { $("#content").slideToggle("slow"); $(".menu").toggleClass("active"); return false // сдвигается меню, появляется контент } }); }); </script> <body> <div class="box"> <div class="menu"> <a href="#" class="button">Show content</a> </div> <div id="content">Content</div> </div> </body> </html> @charset "utf-8"; /* CSS Document */ body {background-color:#999; margin: 0px; padding: 0px;} .box { margin-left: auto; margin-right: auto; margin-top: 100px; width: 600px;} .button {color:#333; text-decoration:none; margin-top: 15px; margin-left: 15px;} .menu { width: 150px; height: 200px; margin-left: auto; margin-right: auto; background-color: #FFF;} .active {float: left; clear: both;} #content {background-color: #C00; color: #FFF; text-decoration: none; width: 450px; background-color: #333; height: 300px; float:right; display: none;} |
Задачу решил, тему можно удалять
|
Часовой пояс GMT +3, время: 00:49. |