2012-01-29 39 views
0

在一個div的效果我有兩個相同大小的圖像滿了,我想實現與jQuery動畫和絕對位置

<img id="second image"> 
<img id="first image"> 

的效果是:

1.已經顯示的圖像(第一圖像)崩潰與底部固定的,第二圖像輥來與頂部固定 2.然後我插入第一圖像之前在代碼第二圖像,利用CSS位置而改變,就像上面

第一步做得很好,但在第二步驟不起作用

the code and example is here

請幫幫我,謝謝

+0

如果我改變了文件,你可以看到的變化?如果是的話,看看並告訴這是你想要的 – Hadas 2012-01-29 14:08:11

+0

@哈達斯:你可以改變文件,但你應該按下菜單中的更新按鈕,或創建另一個文件,它不需要登錄 – hh54188 2012-01-29 14:37:05

+0

Alaa Badran的答案對你有好處?你想讓動畫像一個圓圈?並一直繼續下去? – Hadas 2012-01-29 14:40:59

回答

0

這是你想要的東西的更新,希望這個作品,你到底要:

var stimer; 
var updown = true; 
$(function() { 
    function circling(){ 
     if(updown === true){ 
       $('#up').css('top',0).animate({ height: "59px" }, 1000); 
      $('#down').css('top',0).animate({ height: 0, top:'59px' }, 1000); 
       updown = false; 
      } else { 
       $('#up').animate({ height: "0",top:'59px' }, 1000); 
       $('#down').css('top',0).animate({ height: '59px' }, 1000); 
       updown = true; 
      } 
    } 
    stimer = setInterval(function(){circling();}, 2000); 
}); 

也將它添加到CSS

h1{overflow:hidden;} 
+1

耶!!!非常感謝你! – hh54188 2012-01-29 15:23:05

0

這裏是解決方案: 我更新了2線 1)$( '#向下')的CSS({頂: 「0」}); 爲 $('#down')。css({top:「59px」}); ,而此框在摺疊時應位於此位置。

2)行: $('#down')。animate({height:「59px」,'top':'0'},{duration:1000}); 爲'頂部'屬性設置動畫。

下面是它的代碼看起來應該像:

 $(function() { 
     function x() { 
       $('#down').insertBefore('#up'); 
       // The line was update 
       $('#down').css({ top: "59px" }); 
       $('#up').css({ bottom: "0" }); 
      // Also this line was updated. 
      $('#down').animate({ height: "59px",'top':'0' }, { duration: 1000 }); 
       $('#up').animate({ height: "0" }, { duration: 1000 }); 

     } 

     $('#down').animate({ height: "0" }, { duration: 1000 }); 
     $('#up').animate({ height: "59px" }, { duration: 1000, complete: x }); 
    }); 
+0

不行,我想要的是:黃色向下第二輪,它應該從紅色的頂部,而不是從底部 – hh54188 2012-01-29 14:38:38

+0

作爲哈達斯說,像一個圓圈 – hh54188 2012-01-29 14:52:26

+0

:不不不不不,不,它還是不是我想要的,它更進一步...... – hh54188 2012-01-29 14:58:39

0

使用此變化:

css: 
#up{ background:red;}   
#down{ background:yellow;} 
.top{ height:0px; top:0px; } 
.bottom{ height:59px; bottom:0px;} 

的javascript:

$(function() { 
    function x() { 
     $('h1').last().insertBefore($('h1').first()); 

     $('h1').first().removeClass(); 
     $('h1').first().addClass("top"); 
     $('h1').last().removeClass(); 
     $('h1').last().addClass("bottom"); 

     $('h1').first().animate({ height: "59px"}, { duration: 1000}); 
     $('h1').last().animate({ height: "0" }, { duration: 1000,complete:x }); 


    } 
    $('#down').addClass('bottom'); 
    $('#up').addClass('top'); 
    $('#down').animate({ height: "0" }, { duration: 1000 }); 
    $('#up').animate({ height: "59px" }, { duration: 1000, complete: x }); 
});