简体   繁体   中英

What's wrong with this (animate) jquery code?

var object = $('#object');
var start = $('#start');
var normal = $('#object_normal');
normal.hide();

start.on('click', function(){
    object.animate({margin-bottom:'0px'}, 3000, function(){
                normal.fadeIn(700) ;  
                   });
});

can anyone explain why this code does not work? The variables and method outside the function do work. But when I add the function below, suddenly nothing happens. So there must be something wrong with the function.

This line is the problem:

object.animate({margin-bottom:'0px'}, 3000, function(){

(the property to be animated is interpreted as margin minus bottom.)

Instead, use this:

object.animate({marginBottom:'0px'}, 3000, function(){

You should get into the habit of watching the console log when testing your code; the error message you would have received would have shown you exactly where the problem was.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM