Fixed/sticky сайдбар

vinsbg

Registered
Здравейте,

дайте идея и ако има някой туториал за следното нещо-
Имам страница, която е много дълга (разбирай скролва се много, докато се стигне футъра) и сайдбар от дясната страна. Това, което искам и се чудя дали е възможно, когато се скролва надолу текущия сайдбар да бъде заменен с друг, който да стои фиксиран там, докато се скролва надолу..

Съответно, когато се върне в началото на страницата да се върне стария сайдбар.

Предполагам тук ще ми трябва javascript или?
 
HTML:
<html>
<head>
<title>sticky sidebar</title>
<script type="text/javascript">
window.onscroll = function(){
document.getElementById("sidebara").style.display = "none";
document.getElementById("sidebarb").style.display = "block";
};
</script>
<head>
<body>
<div id="sidebara" style="position:absolute;right:0;width:300px;height:100%;background-color:Orangered;">
This is the default sidebar.
</div>
<div id="sidebarb" style="display:none;position:fixed;right:0;width:300px;height:100%;background-color:Orange;">
This is another sidebar to replace the default one.
</div>
<div style="width:1px; height:2048px;float:left;"></div>
</body>
</html>

Това ли?
 
gLaVoReZa каза:
HTML:
<html>
<head>
<title>sticky sidebar</title>
<script type="text/javascript">
window.onscroll = function(){
document.getElementById("sidebara").style.display = "none";
document.getElementById("sidebarb").style.display = "block";
};
</script>
<head>
<body>
<div id="sidebara" style="position:absolute;right:0;width:300px;height:100%;background-color:Orangered;">
This is the default sidebar.
</div>
<div id="sidebarb" style="display:none;position:fixed;right:0;width:300px;height:100%;background-color:Orange;">
This is another sidebar to replace the default one.
</div>
<div style="width:1px; height:2048px;float:left;"></div>
</body>
</html>

Това ли?
Да, но възможно ли е при скролване нагоре да върне стария(първия) сайдбар.

syneidesys каза:
Не точно това.. Трябва ми да сменя един сайдбар с друг. Заглавието на темата малко подвежда и то, но не измислих как точно да го напиша.
 

Back
Горе