Ho fatto questo in script per creare un animazione ( espandi - richiudi ), ma quando lo eseguo ottengo "this.obj has not properties" riferito ad "this.obj.style.overflow = 'hidden'". Penso che sia perchè "window.setInterval" esegue la funzione "this.collapse" in un ambito dove "this.obj" non è definito. Vorrei un aiuto per far funzionare lo script così com'è, senza passare parametri in ogni funzione!
codice:function Toggle ( trigger, obj, speed ) { this.intervalId = null ; this.trigger = trigger ; this.obj = obj ; this.speed = speed ; this.create = function () { window.clearInterval ( this.intervalId ) ; if ( !this.speed ) this.speed = parseInt ( 100 / 30 ) ; if ( !this.obj.style.display ) { this.trigger.innerHTML = '+' ; this.intervalId = window.setInterval ( this.collapse, 1 ) ; } else { this.trigger.innerHTML = '-' ; this.intervalId = window.setInterval ( this.expand, 1 ) ; } } this.expand = function () { this.obj.style.display = '' ; if ( this.getHeight () < 100 ) { this.obj.style.height = this.getHeight () + this.speed + 'px' ; } else { this.obj.style.height = 100 + 'px' ; window.clearInterval ( this.intervalId ) ; } } this.collapse = function () { this.obj.style.overflow = 'hidden' ; if ( this.getHeight () > 0 ) { if ( this.speed > this.getHeight () ) this.obj.style.height = 0 + 'px' ; else this.obj.style.height = this.getHeight () - this.speed + 'px' ; } else { this.obj.style.display = 'none' ; window.clearInterval ( this.intervalId ) ; } } this.getHeight = function () { return this.obj.offsetHeight ; } }

Rispondi quotando