Помогите сократить код!
<input type="button" value="На весь экран" class="button1-check-act" onclick="full('swf-zoom');fullbackgraund('litebox-full');fulloverflow('bd');fullbuttoff('toolbar-litebox')" ></input>
<script type="text/javascript">
// На весь экран
function full(nodeId) {
var node = document.getElementById(nodeId);
if (node){window.scrollTo(0,0);node.style.margin = 'auto';node.style.zIndex = '50';node.style.height = '85%';node.style.width = '85%';node.style.left = '32.5%';node.style.marginLeft = '-25%';node.style.top = '8%'; node.style.transition = 'all .218s ease 0s';}
}
function fullpositionFIXED(nodeId) {
var node = document.getElementById(nodeId);
if (node){node.style.display = 'block'; }
}
function fullbackgraund(nodeId) {
var node = document.getElementById(nodeId);
if (node){node.style.display = 'block'; }
}
function fulloverflow(nodeId) {
var node = document.getElementById(nodeId);
if (node){node.style.overflow = 'hidden'; }
}
function fullbuttoff(nodeId) {
var node = document.getElementById(nodeId);
if (node){node.style.display = 'block'; }
}
|
Воспользуйся онлайн-обфускатором кода.
А если серьезно - проще переписать чем копаться в этом дерьме. Че кнопка должна делать-то? |
node.style.margin = 'auto';node.style.zIndex = '50';node.style.height = '85%';node.style.width = '85%';node.style.left = '32.5%';node.style.marginLeft = '-25%';node.style.top = '8%'; node.style.transition = 'all .218s ease 0s';} напиши класс в цсс, например так:
.myclass {
margin: auto;
z-index: 50;
...
}
и присваивай своему элементу этот класс, можно для начала так: node.setAttribute('class', 'myclass'); |
Цитата:
|
вот те рабочий пример, изучай:
<html>
<head>
<title>example</title>
<style>
.cl {
width: 100px;
height: 30px;
border: 1px solid silver;
}
.cl-one {
background-color: red;
font-weight: bold;
}
.cl-two {
background-color: black;
color: green;
border-radius: 5px;
font-style: italic;
}
</style>
</head>
<body>
<div class="cl" onclick="updateClass(this, 'cl-one');">123</div>
<div class="cl" onclick="updateClass(this, 'cl-two');">345</div>
<script>
function updateClass (ths, nameCl) {
var listCl = ths.getAttribute('class').split(' '),
index = listCl.indexOf(nameCl);
if (index == -1) {
listCl.push(nameCl);
} else {
listCl.splice(index, 1);
}
ths.setAttribute('class', listCl.join(' '));
}
</script>
</body>
</html>
|
skrudjmakdak, про .className не слышал? А вообще:
<html>
<head>
<title>example</title>
<style>
.cl {
width: 100px;
height: 30px;
border: 1px solid silver;
}
.cl-one {
background-color: red;
font-weight: bold;
}
.cl-two {
background-color: black;
color: green;
border-radius: 5px;
font-style: italic;
}
</style>
</head>
<body>
<div class="cl" onclick="classList.toggle('cl-one');">123</div>
<div class="cl" onclick="classList.toggle('cl-two');">345</div>
</body>
</html>
Кроссбраузерность? classList.js в помощь. |
| Часовой пояс GMT +3, время: 00:31. |