Поднять/Отпустить елементы
<script> function gettop() { var a = document.getElementById('div1').style.top; alert('a'); if (a != 50px) { document.getElementById('div1').style.top = "50px"; return false; } else { document.getElementById('div1').style.top = "150px"; return false;} } </script> <a href="" onclick="gettop();" style="position: absolute; top: 150px" id="div1">бла бла бла</a> где ошибка подскажите почему не работает? по клику хочу поднять елемент на указааную высоту TOP а по второму клику опустить на ту высоту TOP которая была |
даже alert('a'); чето не выводит по клику (ето я так протестить вставил его там быть недолжно)
|
<script> function gettop() { var a = document.getElementById('div1').style.top; if (a != '50px') { document.getElementById('div1').style.top = "50px"; return false; } else { document.getElementById('div1').style.top = "150px"; return false;} } </script> <a href="" onclick="gettop();" style="position: absolute; top: 150px;" id="div1">бла бла бла</a> так поменял начало блымать просто при клике |
новый вася,
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> </head> <body> <script> function gettop() { var a = document.getElementById('div1').style.top; if (a != '50px') { document.getElementById('div1').style.top = "50px"; } else { document.getElementById('div1').style.top = "150px"; } return false; } </script> <a href="" onclick="return gettop();" style="position: absolute; top: 150px;" id="div1">бла бла бла</a> </body> </html> |
Новый вася, что значит "блымать"?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head> <body> <a href="" onclick="gettop(event);" style="position: absolute; top: 150px" id="div1">бла бла бла</a> <script> function gettop(e){ e.preventDefault(); var height = { a: '150px', b: '50px' } e.target.style.top == height.a ? e.target.style.top = height.b : e.target.style.top = height.a } </script> </body> </html> |
Ронни огромное спасибо =)
|
Цитата:
|
Часовой пояс GMT +3, время: 01:04. |