javascript - JS Exception : animate is not a function - Stack Overflow

I've an image inside a div, and the following Javascript code:function animate_down(key1, key2) {

I've an image inside a div, and the following Javascript code:

function animate_down(key1, key2) 
{
   cimage = document.getElementById('sslot_img' + key1);
   var topval = cimage.offsetTop;
   if (topval == -416) {
        cimage.animate({ top: '0px' }, 5000);
   }
   else {
        topval = topval - 32;
        var toptxt = { 'top': topval.toString() };
        cimage.animate(toptxt, 5000);
    }
}

I've test it in Firebug, when the debugger reaches .animate function it's throwing :

cimage.animate is not a function 

what am i missing?

I've an image inside a div, and the following Javascript code:

function animate_down(key1, key2) 
{
   cimage = document.getElementById('sslot_img' + key1);
   var topval = cimage.offsetTop;
   if (topval == -416) {
        cimage.animate({ top: '0px' }, 5000);
   }
   else {
        topval = topval - 32;
        var toptxt = { 'top': topval.toString() };
        cimage.animate(toptxt, 5000);
    }
}

I've test it in Firebug, when the debugger reaches .animate function it's throwing :

cimage.animate is not a function 

what am i missing?

Share Improve this question edited May 30, 2013 at 10:08 toro2k 19.2k8 gold badges65 silver badges71 bronze badges asked Sep 7, 2012 at 12:58 Alaa AlweishAlaa Alweish 9,10617 gold badges61 silver badges85 bronze badges 1
  • probably your code doesn't contain the latest version of jquery. – Codegiant Commented Sep 7, 2012 at 13:01
Add a ment  | 

4 Answers 4

Reset to default 4

getElementById is not a jQuery function, and will not yield a jQuery object. animate is only available on jQuery objects. You need to either wrap your cimage:

$(cimage).animate( ... )

or fetch it through jQuery rather than getElementById

var cimage = $('#sslog_img' + key1);

Note that if you go with the latter option, cimage will not have an offsetTop property, but rather, you'd have to use

cimage.offset().top

or

cimage[0].offsetTop

.animate() is a jquery function, you need to use it on a jquery object.

instead of

 cimage = document.getElementById('sslot_img' + key1);

use

 var cimage = $('#sslot_img' + key1);

try with

cimage = $('#sslot_img' + key1);
cimage = document.getElementById('sslot_img' + key1);

Is not a jQuery Object.

$('#sslot_img' + key1');

will return one you can animate.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744711823a4589386.html

相关推荐

  • javascript - JS Exception : animate is not a function - Stack Overflow

    I've an image inside a div, and the following Javascript code:function animate_down(key1, key2) {

    17小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信