2012-05-17 107 views
1

你好,我有一個寬度爲500px的DIV。jQuery從左到右縮小寬度

我試圖減少從500px到0px和從0px到500px的動畫的寬度。

只有一個問題,即DIV從右向左減少。

我想要相反的東西。

從一開始,寬度將從左到右縮小並動畫化,然後從右到左從0px增加到500px。

我該怎麼用jQuery做到這一點?

感謝所有幫助

EDITED

function animateText(px) { 
 $('#slidetext').animate({ 
  'width' : px 
 }); 
} 
+0

請附上您的代碼:) – mattytommo

+1

只是加了我的jQuery代碼小片段 –

+1

http://www.learningjquery.com/2009/02/slide-elements-in-different-directions –

回答

1

這是可能的,但你需要使用position: absolute,看到我的小提琴HERE

function animateText(px) { 
    $('#slidetext').animate({ 
     left: $("#slidetext").width(), 
     width: px 
    }); 
} 
0

你是想爲這個

jsFiddle

$("#div2").animate({ 
      'width':'50%', 
      'left':'49%' 
},1000);​ 
0

看到這個例子小提琴:http://jsfiddle.net/TC9Mn/

的想法是與position: relative包裝AA容器內的元素,並分配給你想以這種方式來製作動畫position: absoluteright: 0

元素寬度從左到右變化

0

試試這個,這可以使用css3沒有你唱任何JavaScript/jQuery代碼。下面是我的小提琴。
使用@keyframeanimation財產 http://jsfiddle.net/eQMyq/2/

+0

在IE中爲你工作嗎?在Chrome中爲我做了,但在IE中沒有:) – mattytommo

+0

啊從頭開始,@keyframes是一切**但IE ** http://www.w3schools.com/cssref/css3_pr_keyframes.asp – mattytommo

+0

查看此鏈接一次http://css-tricks.com/snippets/css/webkit-keyframe-animation-syntax/ – Valli69