var leftdis;
leftdis = document.getElementById('left_bar');
function leftmn() {
if (leftdis.style.display == 'none') {
leftdis.style.display = 'block';
} else {
leftdis.style.display = 'none';
}
}
#left_bar {
display: none;
position: fixed;
width: 200px;
height: 100%;
background: #ddd;
}
#left_triger {
height: 24px;
width: 50px;
position: absolute;
top: 13px;
left: 5px;
display: block;
}
<a href="" id="left_triger" onclick="leftmn()">Menu</a>
js:
var leftdis;
leftdis = document.getElementById('left_bar');
function leftmn(){
if (leftdis.style.display == 'none'){
leftdis.style.display = 'block';
} else {
leftdis.style.display = 'none';
}
}
css:
#left_bar{
display: none;
position: fixed;
width: 200px;
height: 100%;
background: #ddd;
}
#left_triger{
height: 24px;
width: 50px;
position: absolute;
top: 13px;
left: 5px;
display: block;
}
Вопрос: Почему не хочет работать функция? Фишка в том, что на другом проекте работает..
Не было блока id="left_bar", после onclick не было return false; выполнялся поиск элемента до его инициализации.
function leftmn() {
var leftdis;
leftdis = document.getElementById('left_bar');
if (leftdis.style.display == 'none') {
leftdis.style.display = 'block';
} else {
leftdis.style.display = 'none';
}
}
#left_bar {
display: none;
position: fixed;
width: 200px;
height: 100%;
background: #ddd;
}
#left_triger {
height: 24px;
width: 50px;
position: absolute;
top: 13px;
left: 5px;
display: block;
}
<a href="" id="left_triger" onclick="leftmn();return false;">Menu</a>
<div id="left_bar" style="display:none">bar</a>
Сборка персонального компьютера от Artline: умный выбор для современных пользователей