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?
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?
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!
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>
purtroppo mi da errore e non javascript non funziona, sono disperata, un script semplice
ma esistono due elementi con id = "example" e id = "example2"?
I DON'T Double Click!
no io devo inserire solo examle2
infatti, eliminanto new horizontalMarquee('example');, mi va bene tutto. grazie mille
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