![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:28
|
без статуса
|
|
Регистрация: 25.05.2012
Сообщений: 8,219
|
|
Hekumok,
алерт всуньте в свою функцию - жмите кнопку и смотрите
alert( document.body.style.backgroundColor );
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:29
|
что-то знаю
|
|
Регистрация: 24.05.2009
Сообщений: 5,176
|
|
<input onclick="color();" value="Жми" type="button">
<script type="text/javascript">
function toHexColor( color ) {
return color.replace( /rgba?\(([^\)]+)\)|#([a-f0-9]{6}|[a-f0-9]{3})/ig, function( m, rgb, hex ) {
if ( rgb = /([0-9\.]+)(\%?)\s*,\s*([0-9\.]+)(\%?)\s*,\s*([0-9\.]+)(\%?)\s*(?:,\s*([0-9\.]+))?/g.exec( rgb || "" ) ) {
hex = parseInt( rgb[2] ? rgb[1] * 2.55 : rgb[1] ).toString( 16 ).replace( /^(.)$/, '0$1' ) +
parseInt( rgb[4] ? rgb[3] * 2.55 : rgb[3] ).toString( 16 ).replace( /^(.)$/, '0$1' ) +
parseInt( rgb[6] ? rgb[5] * 2.55 : rgb[5] ).toString( 16 ).replace( /^(.)$/, '0$1' );
m = rgb[ 7 ] == "" || rgb[ 7 ] === undefined ? 1 : parseFloat( rgb[ 7 ] );
} else if ( hex && ( m = 1 ) ) {
hex = hex.replace( /^(.)(.)(.)$/, "$1$1$2$2$3$3" );
} else {
return m;
}
return "#" + hex;
});
}
function color() {
if ( toHexColor( document.body.style.backgroundColor ) == '')
return document.body.style.backgroundColor='#f00';
if ( toHexColor( document.body.style.backgroundColor ) == '#ff0000')
return document.body.style.backgroundColor='#0f0';
if ( toHexColor( document.body.style.backgroundColor ) == '#00ff00')
return document.body.style.backgroundColor='#f00';
}
</script>
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:30
|
без статуса
|
|
Регистрация: 25.05.2012
Сообщений: 8,219
|
|
devote,
Ну вон жа палитру текущих цветов браузера в его собственном формате - подставлять и сравнивать
Свои цвета задаём в палитре - а считываем браузерные
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:32
|
что-то знаю
|
|
Регистрация: 24.05.2009
Сообщений: 5,176
|
|
Deff,
можно но массив огромный получится, если в него впихнуть всю палитру. Хотя если тока нужные значения то да. Норм.
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:33
|
без статуса
|
|
Регистрация: 25.05.2012
Сообщений: 8,219
|
|
devote,
Ти мож пихать динамически в один и тот жа span и считывать (*мну по быстрому - попонятней пытался
Последний раз редактировалось Deff, 10.06.2012 в 23:42.
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:40
|
![Аватар для Hekumok](https://javascript.ru/forum/image.php?u=21338&dateline=1344715033) |
✔
|
|
Регистрация: 04.06.2012
Сообщений: 513
|
|
Сообщение от devote
|
при том что ты пытаешься сравнить значение "#f00" со значением "rgb( 255, 0, 0 )" это разные значения и они всегда будут не равны, тем самым условие твое никогда не сработает
|
A, спасибо, понял =)
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:42
|
что-то знаю
|
|
Регистрация: 24.05.2009
Сообщений: 5,176
|
|
Сообщение от Deff
|
Ти мож пихать динамически и считывать*мну по быстрому и попонятней
|
Никто не спорит можно и проще конечно:
<input onclick="color();" value="Жми" type="button">
<script type="text/javascript">
var toConvertedColor = (function( b ){
return function( color ) {
b.style.color = color;
return b.style.color;
}
})( document.createElement( 'b' ) );
function color() {
if ( document.body.style.backgroundColor == '')
return document.body.style.backgroundColor='#f00';
if ( document.body.style.backgroundColor == toConvertedColor( '#f00' ) )
return document.body.style.backgroundColor='#0f0';
if ( document.body.style.backgroundColor == toConvertedColor( '#0f0' ) )
return document.body.style.backgroundColor='#f00';
}
</script>
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:44
|
![Аватар для Hekumok](https://javascript.ru/forum/image.php?u=21338&dateline=1344715033) |
✔
|
|
Регистрация: 04.06.2012
Сообщений: 513
|
|
Сообщение от devote
|
<input onclick="color();" value="Жми" type="button">
<script type="text/javascript">
function toHexColor( color ) {
return color.replace( /rgba?\(([^\)]+)\)|#([a-f0-9]{6}|[a-f0-9]{3})/ig, function( m, rgb, hex ) {
if ( rgb = /([0-9\.]+)(\%?)\s*,\s*([0-9\.]+)(\%?)\s*,\s*([0-9\.]+)(\%?)\s*(?:,\s*([0-9\.]+))?/g.exec( rgb || "" ) ) {
hex = parseInt( rgb[2] ? rgb[1] * 2.55 : rgb[1] ).toString( 16 ).replace( /^(.)$/, '0$1' ) +
parseInt( rgb[4] ? rgb[3] * 2.55 : rgb[3] ).toString( 16 ).replace( /^(.)$/, '0$1' ) +
parseInt( rgb[6] ? rgb[5] * 2.55 : rgb[5] ).toString( 16 ).replace( /^(.)$/, '0$1' );
m = rgb[ 7 ] == "" || rgb[ 7 ] === undefined ? 1 : parseFloat( rgb[ 7 ] );
} else if ( hex && ( m = 1 ) ) {
hex = hex.replace( /^(.)(.)(.)$/, "$1$1$2$2$3$3" );
} else {
return m;
}
return "#" + hex;
});
}
function color() {
if ( toHexColor( document.body.style.backgroundColor ) == '')
return document.body.style.backgroundColor='#f00';
if ( toHexColor( document.body.style.backgroundColor ) == '#ff0000')
return document.body.style.backgroundColor='#0f0';
if ( toHexColor( document.body.style.backgroundColor ) == '#00ff00')
return document.body.style.backgroundColor='#f00';
}
</script>
|
О.о до такого кода я еще не дорос
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:47
|
без статуса
|
|
Регистрация: 25.05.2012
Сообщений: 8,219
|
|
![Blink](https://javascript.ru/forum/images/smilies/blink.gif) Почему -то все одно -синего нет ??? (Опера - ток -красный - и зелёный
|
|
![Старый](/forum/images/ca_serenity/statusicon/post_old.gif)
10.06.2012, 23:49
|
![Аватар для Hekumok](https://javascript.ru/forum/image.php?u=21338&dateline=1344715033) |
✔
|
|
Регистрация: 04.06.2012
Сообщений: 513
|
|
Сообщение от Deff
|
Можно текущую поллитру своять
<div style=position:absolute;z-index:-120;">
<span id=color1 style="background-color:#FF0000">a</span>
<span id=color2 style="background-color:#0000FF">a</span>
<span id=color3 style="background-color:#00FF00">a</span>
</div>
<script type="text/javascript">
var color=[];
color.push(document.getElementById('color1').style.backgroundColor)
color.push(document.getElementById('color2').style.backgroundColor)
color.push(document.getElementById('color3').style.backgroundColor)
</script>
|
Объясните поподробней, плиз, что и как, я ведь не проф, а только начинающий почти =)
|
|
|
|