Плавающий блок с помощью jquery (или position:fixed относительно родительского блока)
Встала задача сделать position:fixed относительно родительского блока. При поиске в Интернете наткнулся на интересный jquery скриптик, делающий подобную вещь.
Приступим к коду, из которого сразу становится все понятно:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | <!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> <style type="text/css"> #main { width:900px; margin:0 auto; } .colLeft { width:70%; float:left; } .colRight { float:right; width:20%; } h1{ background:#CCC; padding:50px; } #fixed { background:#CCC; padding:20px; } </style> <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script> <script type="text/javascript"> $(function() { var offset = $("#fixed").offset(); var topPadding = 15; $(window).scroll(function() { if ($(window).scrollTop() > offset.top) { $("#fixed").stop().animate({marginTop: $(window).scrollTop() - offset.top + topPadding}); } else {$("#fixed").stop().animate({marginTop: 0});};}); }); </script> </head> <body> <div id="main"> <h1>Плавающий блок. Прокрутите страницу вниз</h1> <div class="colLeft""colRight"> <div id="fixed">Я зафиксированный блок</div> </div> </div> </body> </html> |
Только анимируется тут конечно же margin-top и никакого position-a нет. Но если вдруг нужно блок #fixed сделать поверх чего-либо, то можно задать ему position:absolute и анимировать свойство top.
Один из плюсов этого способа, что блок не заезжает на шапку, но при прокрутке вниз прилипает к верхнему краю окна.
Fatal error: Call to undefined function wp_related_posts() in /home/k/kazanets/htmlcssinfo/public_html/wp-content/themes/htmlcsstheme/single.php on line 70