Foros del Web » Programando para Internet » Javascript »

no lee javascript, ni poniendo lo abajo, porque??porque se ponen antes </body>

Estas en el tema de no lee javascript, ni poniendo lo abajo, porque??porque se ponen antes </body> en el foro de Javascript en Foros del Web. hola muy buenas, Estoy intentando resolver, porque algunas funciones de javascript relacionadas con jquery, no la interpretan poniendolo en el head,,, he visto en un ...
  #1 (permalink)  
Antiguo 08/11/2010, 17:43
Avatar de gachon  
Fecha de Ingreso: septiembre-2004
Ubicación: En Google
Mensajes: 462
Antigüedad: 19 años, 7 meses
Puntos: 3
no lee javascript, ni poniendo lo abajo, porque??porque se ponen antes </body>

hola muy buenas,
Estoy intentando resolver, porque algunas funciones de javascript relacionadas con jquery, no la interpretan poniendolo en el head,,, he visto en un ejemplo de web que tengo que esta puesto antes del final de la etiqueta del </body> y lo he intentado cambiar al head y no funciona,,,, y ahora para colmo estoy intentando poner un slider jquery de imagenes, y no me funciona tanto en el head como abajo,,,
me podrian explicar el porque,de porque se ponen los archivos javascript antes del </body> y como se puede arreglar.
muchas gracias y espero vuestra ayuda
  #2 (permalink)  
Antiguo 08/11/2010, 20:52
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: no lee javascript, ni poniendo lo abajo, porque??porque se ponen antes </b

Probablemente, porque en el código accedes elementos del DOM que todavía no existen. Puedes usar el evento ready para lo que necesitas (ya que estás usando jQuery)
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 09/11/2010, 07:15
Avatar de gachon  
Fecha de Ingreso: septiembre-2004
Ubicación: En Google
Mensajes: 462
Antigüedad: 19 años, 7 meses
Puntos: 3
Respuesta: no lee javascript, ni poniendo lo abajo, porque??porque se ponen antes </b

muchas gracias por la constestacion estoy intentando hacerlo con el ready y no me funciona,,,
he hecho unas cuantas comprobaciones y me dado cuenta que quitando el codigo que voy a poner me funciona el slider, el problema esta que si quito ese codigo entonces el scroll no me funciona, alguien me puede ayudar??
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.    
  3.              
  4.         jQuery.noConflict();
  5.            
  6.                     Cufon.replace('h1, h2, h3, h4, h5, h6,.comment-author')('h2.gallery-title,.wp-pagenavi,h3#comments',{textShadow:'1px 1px 0px #fff'})('#main-leftarea a',{textShadow:'2px 2px 3px rgba(0, 0, 0, 0.4)', hover: { color: '#ded28e' }});
  7.              
  8.         jQuery("a[class^='fancybox']").fancybox({
  9.             'overlayOpacity'    :   0.7,
  10.             'overlayColor'      :   '#000000',
  11.             'zoomSpeedIn'       :   500,
  12.             'zoomSpeedOut'      :   500
  13.         });
  14.        
  15.         var $rightArea = jQuery('#main-rightarea'),
  16.             rightAreaHeight = $rightArea.height(),
  17.             leftAreaParts = '#main-leftarea, #main-leftarea #right-border',
  18.             $galleryThumb = jQuery('.gallery-area .thumb'),
  19.             $menuLink = jQuery('ul#main-menu li a'),
  20.             menuTopPos = jQuery('#main-leftarea #menu').position().top;
  21.        
  22.         jQuery('span.magnify').css('opacity','0');
  23.        
  24.         if ( rightAreaHeight > 1024 ) jQuery(leftAreaParts).css('height',rightAreaHeight);
  25.  
  26.         $galleryThumb.hover(function(){
  27.             jQuery(this).stop(true, true).animate({top: 6, paddingBottom: 0}, 400).find('span.magnify').stop(true, true).animate({opacity: 1}, 400).end().find('img').stop(true, true).animate({opacity: 0.7}, 400);
  28.         }, function(){
  29.             jQuery(this).stop(true, true).animate({top: 0, paddingBottom: 13}, 400).find('span.magnify').stop(true, true).animate({opacity: 0}, 400).end().find('img').stop(true, true).animate({opacity: 1}, 400);
  30.         });
  31.        
  32.         var windowHash = window.location.hash;
  33.        
  34.         if (windowHash) {
  35.             var activeLink = windowHash.substring(1),
  36.                 $targetLink = $menuLink.parent().find('a[href$=#'+activeLink+']');
  37.            
  38.             $menuLink.removeClass('active');
  39.            
  40.             $targetLink.addClass('active');
  41.            
  42.             jQuery('span#active-arrow').css('top',($targetLink.position().top+menuTopPos-3));
  43.         }
  44.        
  45.         var isHome = true;
  46.        
  47.         if (!isHome) {
  48.             $targetLink = $menuLink.parent().find('a').filter(':last');
  49.             $menuLink.removeClass('active');
  50.             $targetLink.addClass('active');
  51.             jQuery('span#active-arrow').css('top',($targetLink.position().top+menuTopPos-6));
  52.         }
  53.        
  54.         $menuLink.click(function(event){
  55.             if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  56.                 if (jQuery(this).hasClass('external')) return;
  57.                 event.preventDefault();
  58.                 if (jQuery(this).hasClass('active')) return false;
  59.                 if (jQuery("html:animated").length) return false;
  60.                
  61.                 $menuLink.parent().find('a').removeClass('active');
  62.                 jQuery(this).addClass('active');
  63.                
  64.                 var activePos = jQuery(this).parent().position().top,
  65.                     linkId = this.hash.substring(1);
  66.                
  67.                 jQuery('span#active-arrow').animate({top: (activePos + menuTopPos)},500);
  68.                
  69.                 jQuery.scrollTo( '#'+linkId, { duration:500, onAfter:function(){
  70.                         window.location.hash = '#'+linkId;
  71.                     }
  72.                 });
  73.             }
  74.         }).hover(function(){
  75.             jQuery(this).stop().animate({left: '-10px'},200);
  76.         }, function(){
  77.             jQuery(this).stop().animate({left: '0px'},200)
  78.         });
  79.        
  80.         window.setInterval( function() {Cufon.refresh('#main-leftarea a');}, 100 );
  81.    
  82.                     Cufon.now();
  83.                    
  84.             //]]>  
  85.     </script>
que tiene ese codigo que no le deja leer el archivo s3Slider.js. para hacer el slideshow de imagenes
  #4 (permalink)  
Antiguo 09/11/2010, 08:25
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: no lee javascript, ni poniendo lo abajo, porque??porque se ponen antes </b

¿Cuál es el código del Slider?
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #5 (permalink)  
Antiguo 09/11/2010, 09:07
Avatar de Facundo_Nahuel  
Fecha de Ingreso: noviembre-2010
Ubicación: Buenos Aires, Argentina
Mensajes: 32
Antigüedad: 13 años, 5 meses
Puntos: 3
Respuesta: no lee javascript, ni poniendo lo abajo, porque??porque se ponen antes </b

Como dijo David en un principio, no funcionará en el HEAD porque busca elementos que todavía no se crearon.

Para solucionarlo debes meter todo tu código javascript dentro de $(function(){tu código}) o $(document).ready(function(){tu código})


Quedaría así

Código:
$(function(){
jQuery.noConflict();
           
                    Cufon.replace('h1, h2, h3, h4, h5, h6,.comment-author')('h2.gallery-title,.wp-pagenavi,h3#comments',{textShadow:'1px 1px 0px #fff'})('#main-leftarea a',{textShadow:'2px 2px 3px rgba(0, 0, 0, 0.4)', hover: { color: '#ded28e' }});
             
        jQuery("a[class^='fancybox']").fancybox({
            'overlayOpacity'    :   0.7,
            'overlayColor'      :   '#000000',
            'zoomSpeedIn'       :   500,
            'zoomSpeedOut'      :   500
        }); 
        
        var $rightArea = jQuery('#main-rightarea'),
            rightAreaHeight = $rightArea.height(),
            leftAreaParts = '#main-leftarea, #main-leftarea #right-border',
            $galleryThumb = jQuery('.gallery-area .thumb'),
            $menuLink = jQuery('ul#main-menu li a'),
            menuTopPos = jQuery('#main-leftarea #menu').position().top;
        
        jQuery('span.magnify').css('opacity','0');
        
        if ( rightAreaHeight > 1024 ) jQuery(leftAreaParts).css('height',rightAreaHeight);
 
        $galleryThumb.hover(function(){
            jQuery(this).stop(true, true).animate({top: 6, paddingBottom: 0}, 400).find('span.magnify').stop(true, true).animate({opacity: 1}, 400).end().find('img').stop(true, true).animate({opacity: 0.7}, 400);
        }, function(){
            jQuery(this).stop(true, true).animate({top: 0, paddingBottom: 13}, 400).find('span.magnify').stop(true, true).animate({opacity: 0}, 400).end().find('img').stop(true, true).animate({opacity: 1}, 400);
        });
        
        var windowHash = window.location.hash;
        
        if (windowHash) {
            var activeLink = windowHash.substring(1),
                $targetLink = $menuLink.parent().find('a[href$=#'+activeLink+']');
            
            $menuLink.removeClass('active');
            
            $targetLink.addClass('active');
            
            jQuery('span#active-arrow').css('top',($targetLink.position().top+menuTopPos-3));
        }
        
        var isHome = true;
        
        if (!isHome) {
            $targetLink = $menuLink.parent().find('a').filter(':last');
            $menuLink.removeClass('active');
            $targetLink.addClass('active');
            jQuery('span#active-arrow').css('top',($targetLink.position().top+menuTopPos-6));
        }
        
        $menuLink.click(function(event){
            if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
                if (jQuery(this).hasClass('external')) return;
                event.preventDefault();
                if (jQuery(this).hasClass('active')) return false;
                if (jQuery("html:animated").length) return false;
                
                $menuLink.parent().find('a').removeClass('active');
                jQuery(this).addClass('active');
                
                var activePos = jQuery(this).parent().position().top,
                    linkId = this.hash.substring(1);
                
                jQuery('span#active-arrow').animate({top: (activePos + menuTopPos)},500);
                
                jQuery.scrollTo( '#'+linkId, { duration:500, onAfter:function(){
                        window.location.hash = '#'+linkId;
                    }
                }); 
            }
        }).hover(function(){
            jQuery(this).stop().animate({left: '-10px'},200);
        }, function(){
            jQuery(this).stop().animate({left: '0px'},200)
        });
        
        window.setInterval( function() {Cufon.refresh('#main-leftarea a');}, 100 );
    
                    Cufon.now();
 )
  #6 (permalink)  
Antiguo 09/11/2010, 11:34
Avatar de gachon  
Fecha de Ingreso: septiembre-2004
Ubicación: En Google
Mensajes: 462
Antigüedad: 19 años, 7 meses
Puntos: 3
Respuesta: no lee javascript, ni poniendo lo abajo, porque??porque se ponen antes </b

muchas gracias, no se porque cuando lo intente hacer cuando me lo dijo David no me salio, y ahora que he hecho un copia y pega, y la verdad que me sale
muchisimas gracias lo he podido resolver gracias a vosotros

Etiquetas: abajo, ponen
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:14.