您可以使用新的瀏覽器的CSS 100vw財產,但對於舊的瀏覽器可以使用jQuery來獲取窗口的寬度。以下是您的代碼,並在下方進行調整。
(function($) {
$(document).ready(function() {
$('.nav-toggle').click(function(){
var content_selector = $(this).attr('href');
var my_switch = $(this);
//Added variable
var viewPortWidth = $(window).outerWidth();
if (my_switch.hasClass('close_toggle')) {
$(content_selector).slideToggle(function(){
$('.collapsing_footer').animate({
maxWidth: '670'}, 400);
my_switch.removeClass('close_toggle');
});
//Remove resize event bind
jQuery(window).unbind();
} else {
//on resize adjust the max width
jQuery(window).resize(function() {
//reset viewport width variable to current
viewPortWidth = $(window).outerWidth();
$('.collapsing_footer').css({ maxWidth : viewPortWidth });
console.log("here");
});
$('.collapsing_footer').animate({ maxWidth: viewPortWidth }, 600,
function() {
$(content_selector).slideToggle(
function(){
my_switch.toggleClass('close_toggle');
}
);
$('body').animate({ scrollTop: 999999 }, 700);
});
}
});
});
})(jQuery);
如果你有瀏覽器版本檢測,我建議你用它來填充變量viewPortWidth。這裏是關於vw css的文章,也包含瀏覽器支持。 http://css-tricks.com/viewport-sized-typography/
那麼確切的問題是什麼?你的動畫是不是流動的,因爲5000和670的巨大差距?那是對的嗎? – 2014-12-02 17:39:46
對。我正在尋找一種方法來獲得100%的寬度沒有那個瘋狂的5000值 – GCW 2014-12-02 17:42:33