Visualizzazione dei risultati da 1 a 8 su 8

Discussione: errore in javascript

  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2009
    Messaggi
    14

    errore in javascript

    salve a tutti e Buone Feste.
    ho creatola pagina home con elementi di javascript e mi dà errore: 'this.element' è nullo o non è un oggetto. che cosa può sinificare, secondo voi?

  2. #2
    eh, che lo scope all'interno della quale chiami la funzione non ha la variabile element definita.


    N.B: senza un esempio del codice che causa l'errore, mica posso essere più chiaro.
    I DON'T Double Click!

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2009
    Messaggi
    14

    scusami, ecco

    var newsMarquee = Class.create({

    initialize: function(element,options) {
    this.element = $(element);
    this.innerDiv = this.element.down('div');
    this.options = {
    speed: 3,
    control: true
    };
    Object.extend(this.options, options || {});

    this.playScroll();
    if (this.options.control) {
    this.addObserver();
    }
    },

    addObserver: function() {
    this.element.observe('mouseover', this.pauseScroll.bind(this));
    this.element.observe('mouseout', this.playScroll.bind(this));
    },

    playScroll: function(){
    this.scrolling = true;
    this.startScroll();
    },

    pauseScroll: function(){
    if (this.timeout) {
    this.timeout.stop();
    this.scrolling = false;
    }
    },

    startScroll: function(){
    if (this.scrolling) {
    this.timeout = new PeriodicalExecuter(function(){
    this.executeScroll();
    }.bind(this), this.options.speed/100);
    }
    }

    });

    var horizontalMarquee = Class.create(newsMarquee,{

    initialize: function($super,element,options) {
    $super(element,options);

    this.initialWidth = this.element.getWidth();
    this.childWidth = 0;
    this.childs = this.innerDiv.childElements();
    this.childs[0].style.paddingLeft= this.initialWidth+'px';
    this.childs[this.childs.length-1].style.paddingRight= this.initialWidth+'px';
    this.childs.each(function(node) {
    this.childWidth += node.getWidth();
    }.bind(this)
    )
    this.innerDiv.style.width = this.childWidth+'px';
    },

    executeScroll: function() {
    if (this.element.scrollLeft > (this.element.scrollWidth-this.initialWidth)) {
    this.element.scrollLeft = 0;
    }
    this.element.scrollLeft = this.element.scrollLeft+1;
    }

    });


    var verticalMarquee = Class.create(newsMarquee,{

    initialize: function($super,element,options) {
    $super(element,options);
    this.initialHeight = this.element.getHeight();
    this.innerDiv.style.paddingTop = this.initialHeight+'px';
    this.innerDiv.style.paddingBottom = this.initialHeight+'px';
    },

    executeScroll: function() {
    if (this.element.scrollTop>=(this.element.scrollHeigh t-this.initialHeight)) {
    this.element.scrollTop=0;
    }
    this.element.scrollTop = this.element.scrollTop+1;
    }

    });
    ---questo è un file.js, invece in file. html
    ho inserito
    <script type="text/javascript" src="js/prototype.js"></script>
    <script type="text/javascript" src="js/newsMarquee.js"></script>
    <script type="text/javascript">
    Event.observe (window, 'load', function(){
    new horizontalMarquee('example');
    new verticalMarquee('example2');
    });

    </script>

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2009
    Messaggi
    14
    purtroppo mi da errore e non javascript non funziona, sono disperata, un script semplice

  5. #5
    ma esistono due elementi con id = "example" e id = "example2"?
    I DON'T Double Click!

  6. #6
    Utente di HTML.it
    Registrato dal
    Aug 2009
    Messaggi
    14
    no io devo inserire solo examle2

  7. #7
    Utente di HTML.it
    Registrato dal
    Aug 2009
    Messaggi
    14
    infatti, eliminanto new horizontalMarquee('example');, mi va bene tutto. grazie mille

  8. #8
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,304

    Moderazione

    Vedi anche quanto ho scritto in questa discussione.


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.