Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/08/2010, 22:14
berlusconi
 
Fecha de Ingreso: enero-2010
Mensajes: 7
Antigüedad: 14 años, 3 meses
Puntos: 0
Div que se mueve junto con la barra de desplazamiento

Hola.
Primer tema que creo. El tema es el siguiente:

Lo que estoy buscando es un banner que se mueve junto con la barra de dezplazamiento. Pero el problema es que quiero que comienze a deslizarce (el div) a partir de cierta posición.
Yo tengo todo el código para que se desplaze pero lo hace partiendo de determinado margen del body. Si yo amplío ese margen, luego al mover la barra de desplazamiento del navegador permanecerá ese margen y no se verá por completo.

Les paso los códigos. Supongo yo que se soluciona del js, pero no entiendo nada de js.

Este es el html

Código HTML:
Ver original
  1.     <div id="head"></div>
  2. <div id="cuepo">   
  3.   <div id="content"></div>
  4.   <!-- ME PERSIGUE UN BANNER!!! -->
  5.   <DIV style="top: 423px; display: block; " id="floatLayer">
  6.     FDSFDSFDSFDSFDS    </DIV>
  7. </div>
  8. bannerStart(815,14,120);
  9.   <!-- fin de ME PERSIGUE UN BANNER!!! -->
  10. </BODY>
el css sería esto (es algo asi nomas para guia)
Código CSS:
Ver original
  1. #cuerpo {
  2.     background-color:#0066CC;
  3.     width: 900px;
  4. }
  5. #floatLayer {
  6.     position: absolute;
  7.     height:600px;
  8.     width:160px;
  9.     left:825px;
  10.     top:600px;
  11.     bottom:50px;
  12.     z-index: 5;
  13.     border: 0;
  14.     background-color: #00CC66;
  15. }
  16. #content {
  17.     background-color: #CCCCCC;
  18.     height: 800px;
  19.     width:500px;
  20.     margin:10px 10px 10px 10px;
  21.     position:relative;
  22. }
  23. #head{
  24.     background-color: #006699;
  25.     height: 400px;
  26.     width: 900px;
  27.     position: absolute;
  28.     z-index: 10;
  29. }

y el script que lo tengo en una hoja de js es:

Código Javascript:
Ver original
  1. // JavaScript Document
  2.  
  3. var leftMargin = 0;
  4. var bannerWidth = 0;
  5. var topMargin = 0;
  6.  
  7. var slideTime = 1200;
  8. var ns6 = (!document.all && document.getElementById);
  9. var ie4 = (document.all);
  10. var ns4 = (document.layers);
  11. var ie6st = (document.documentElement && document.documentElement.clientWidth);
  12. var bannerEnabled = true;
  13. var bannerTimer = 0;
  14.  
  15. function bannerActivar() {
  16.     bannerEnabled = true;
  17.     bannerTimer = window.setInterval("main()", 10)
  18.    
  19.     if (ie4) document.all.floatLayer.style.display="block"
  20.     if (ns4) document.floatLayer.display="block";
  21.     if (ns6) {
  22.         var fl = document.getElementById("floatLayer")
  23.         fl.style.display="block";
  24.         if (!fl.style.top)
  25.             fl.style.top = document.defaultView.getComputedStyle(fl,null).getPropertyValue("top");
  26.     }
  27. }
  28.  
  29. function bannerDesactivar() {
  30.     bannerEnabled = false;
  31.     if (bannerTimer) {
  32.         window.clearInterval(bannerTimer);
  33.         bannerTimer = 0;
  34.     }
  35.     if (ie4) document.all.floatLayer.style.display="none"
  36.     if (ns4) document.floatLayer.display="none";
  37.     if (ns6) document.getElementById("floatLayer").style.display="none";
  38. }
  39.  
  40. function layerObject(id) {
  41.     if (ns6) {
  42.         this.obj = document.getElementById(id).style;
  43.     }
  44.     else if(ie4) {
  45.         this.obj = document.all[id].style;
  46.     }
  47.     else if(ns4) {
  48.         this.obj = document.layers[id];
  49.     }
  50.     return this.obj;
  51. }
  52. function layerSetup() {
  53.     floatLyr = new layerObject('floatLayer');
  54.     bannerActivar();
  55. }
  56. function floatObject() {
  57.     if (ns4 || ns6) {
  58.         findHt = window.innerHeight;
  59.     } else if(ie4) {
  60.         findHt = document.body.clientHeight;
  61.     }
  62. }
  63. function main() {
  64.     if (bannerEnabled) {   
  65.         if (ns4) {
  66.             this.currentY = document.layers["floatLayer"].top;
  67.             this.scrollTop = window.pageYOffset;
  68.         }
  69.         else if(ns6) {
  70.             this.currentY = parseInt(document.getElementById('floatLayer').style.top);
  71.             this.scrollTop = scrollY;
  72.         } else if(ie6st) {
  73.             this.currentY = floatLayer.style.pixelTop;         
  74.             this.scrollTop = document.documentElement.scrollTop        
  75.         } else if(ie4) {
  76.             this.currentY = floatLayer.style.pixelTop;         
  77.             this.scrollTop = document.body.scrollTop;          
  78.         }
  79.         mainTrigger();
  80.     }
  81. }
  82. function mainTrigger() {
  83.     var newTargetY = this.scrollTop + this.topMargin;
  84.  
  85.     if ( this.currentY != newTargetY ) {
  86.         if ( newTargetY != this.targetY ) {
  87.             this.targetY = newTargetY;         
  88.             floatStart();
  89.         }
  90.         animator();
  91.    }
  92. }
  93. function floatStart() {
  94.     var now = new Date();
  95.     this.A = this.targetY - this.currentY;
  96.     this.B = Math.PI / ( 2 * this.slideTime );
  97.     this.C = now.getTime();
  98.     if (Math.abs(this.A) > this.findHt) {
  99.         this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
  100.         this.A = this.A > 0 ? this.findHt : -this.findHt;
  101.     }
  102.     else {
  103.         this.D = this.currentY;
  104.     }
  105. }
  106. function animator() {
  107.     var now = new Date();
  108.     var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
  109.     newY = Math.round(newY);
  110.     if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
  111.         if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
  112.         if ( ns4 )document.layers["floatLayer"].top = newY;
  113.         if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
  114.     }
  115. }
  116. function bannerStart(left_margin, top_margin, width) {
  117.     leftMargin = left_margin;
  118.     topMargin = top_margin;    
  119.     bannerWidth = width;
  120.        
  121.     if(ns6||ns4) {
  122.         pageWidth = innerWidth - 16;
  123.         pageHeight = innerHeight;
  124.     }
  125.     else if(ie4) {
  126.         pageWidth = document.body.clientWidth;
  127.         pageHeight = document.body.clientHeight;
  128.     }
  129.     layerSetup();
  130.     floatObject();
  131.     checkWidth();
  132.     window.onresize = checkWidth;
  133. }
  134.  
  135. function checkWidth() {
  136.     if(ns6||ns4) {
  137.         pageWidth = innerWidth - 16;
  138.     }
  139.     else if(ie4) {
  140.         pageWidth = document.body.clientWidth;
  141.     }
  142.     if (pageWidth >= (leftMargin + bannerWidth))
  143.         bannerActivar();
  144.     else
  145.         bannerDesactivar();
  146. }

La idea sería.
un div cabecera que se ve completo
debajo de eso un div que contiene otros dos. el de la derecha se mueve con la barra por debajo del head (lo hice como alternativa, pero no es lo que busco). pero yo lo que quiero es que el movimiento del div derecho sea en relacion al div que contiene los otros dos (o sea el que está abajo del div)

Les agradecería si me ayudan y cuanto antes mejor.
Saludos.