我一直試圖解決下面的代碼幾周,但只是無法弄清楚什麼是錯的。當選擇圖標時,下面的菜單從左側滑入和滑出,它也像Facebook應用程序一樣向右移動元素。但是,根據瀏覽器的大小(頁面上的不同元素需要移動),我需要它稍有不同。它在文檔準備就緒時可以正常工作,但是當我調整瀏覽器大小時,它會嘗試多次滑入和滑出,並且不會根據大小進行正確的滑動功能。任何人都可以建議嗎?JQuery根據瀏覽器大小動畫onClick
var menuInitialized = false;
function doMenu() {
$(".c_left, .top_right, .c_right, .c_myaccount, .header_image, .c_footer, .copyright, .accepts, .myaccount, .header_logo").removeAttr('style');
var $menu = $(".c_left");
var width = $(window).width();
var status = 'closed';
if (width < 550) {
if (!menuInitialized) {
$('.icon-menu-2').on('click', function(event) {
alert('small'); //test which is being activated onclick
if (status === 'closed') {
$menu.animate({
width: 185,
marginLeft: 0,
display: 'toggle'
}, 'fast');
$(".top_right, .c_right, .c_myaccount, .c_footer, .copyright, .accepts").animate({
marginLeft: 185,
display: 'toggle'
}, 'fast');
$(".myaccount").animate({
marginRight: -185,
display: 'toggle'
}, 'fast');
return status = 'open';
} else if (status === 'open') {
$menu.animate({
width: 0,
marginLeft: -185,
display: 'toggle'
}, 'fast');
$(".top_right, .c_right, .c_myaccount,.c_footer, .copyright, .accepts").animate({
marginLeft: 0,
display: 'toggle'
}, 'fast');
$(".myaccount").animate({
marginRight: 0,
display: 'toggle'
}, 'fast');
return status = 'closed';
}
});
menuInitialized = true;
}
} else if ((width < 800) && (width > 550)) {
if (menuInitialized) {
$('.icon-menu-2').on('click', function(event) {
alert('large'); //test which is being activated onclick
if (status === 'closed') {
$menu.animate({
width: 185,
marginLeft: 0,
display: 'toggle'
}, 'fast');
$(".top_right, .c_right, .c_myaccount, .header_image, .c_footer, .copyright, .accepts").animate({
marginLeft: 185,
display: 'toggle'
}, 'fast');
$(".myaccount, .header_logo").animate({
marginRight: -185,
display: 'toggle'
}, 'fast');
return status = 'open';
} else if (status === 'open') {
$menu.animate({
width: 0,
marginLeft: -185,
display: 'toggle'
}, 'fast');
$(".top_right, .c_right, .c_myaccount, .header_image,.c_footer, .copyright, .accepts").animate({
marginLeft: 0,
display: 'toggle'
}, 'fast');
$(".myaccount, .header_logo").animate({
marginRight: 0,
display: 'toggle'
}, 'fast');
return status = 'closed';
}
});
menuInitialized = false;
}
}
}
$(document).ready(doMenu);
$(window).resize(doMenu);
您可以製作小提琴嗎? – Mooseman
我試圖做一個簡化版本在這裏:http://jsfiddle.net/cDppA/7/,但我甚至不能得到點擊功能工作 – LeeTee