2012-01-17 70 views

回答

1

請使用.animate()的寬度減少到0動畫:

$('#my-id').animate({ width : 0 }, 1000); // slide left the div 

滑塊向右更復雜......

0

如果您的div有溢出這可以工作:隱藏

$("#test").animate({width:0},500,function(){$(this).hide()}) 
+0

如果您的div有邊框,您需要特別隱藏。如果沒有,你可以使用@ WouterJ的解決方案 – 2012-01-17 22:21:10

3

這是一個快速的jQuery插件,可能有幫助嗎?

jQuery.fn.slideLeftHide = function(speed, callback) { 
    this.animate({ 
     width: "hide", 
     marginLeft: "hide", 
     marginRight: "hide" 
    }, speed, callback); 
} 

jQuery.fn.slideLeftShow = function(speed, callback) { 
    this.animate({ 
     width: "show", 
     marginLeft: "show", 
     marginRight: "show" 
    }, speed, callback); 
} 

要使用像這樣:

$("#elemID").slideLeftHide(300); 

和示範開始一個FIDDLE