您可以使用新的浏览器的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