i wrote a jquery function and from there i try to toggle opacity with animate function but my code is not working. can anyone tell me where is the fault. thanks
jQuery.fn.blindToggle = function (speed, easing, callback) {
var _opacity = 0;
var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));
$(this).toggle(function () {
_opacity = 0;
},
function () {
_opacity = 1;
});
alert(_opacity);
return this.animate({ opacity: _opacity,
marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h
}, speed, easing, callback);
};
jQuery’s
animatehas a shortcut for what you’re trying to do:Then you don’t need to implement that logic yourself.