PDA

View Full Version : Script chạy tốt trên IE nhung die trên FF?!



shpy
20-05-2009, 10:07
Chào các bạn.
Do tiêu đề ngắn quá nên cũng chưa nó rõ ý. Mình mới mò mẫm script,lụm được cái script này về học tập nhưng thấy nó cỉ chạy trên IE , còn trên FF không chạy.

Trong những script khác ngừoi ta hướng dẫn mình (if IE thì .... ; if FF thì ...) , lúc đó inh còn hiể sơ sơ là tại sao FF không chạy ki IE chạy. Còn cái script ày mình mù rồi. Bạn nào huớng dẫn giúp mình và làm sau để sửa cho nó chạy cả IE và FF?

Link và code đây ạ:

http://javascript.internet.com/page-details/hexadecimal-color-wheel.html





<!-- THREE STEPS TO INSTALL HEXADECIMAL COLOR WHEEL:

1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag
3. Put the last coding into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: D10n (biab@iinet.net.au) -->
<!-- Web Site: http://www.iinet.net.au/~biab -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
addary = new Array(); //red
addary[0] = new Array(0,1,0); //red green
addary[1] = new Array(-1,0,0); //green
addary[2] = new Array(0,0,1); //green blue
addary[3] = new Array(0,-1,0); //blue
addary[4] = new Array(1,0,0); //red blue
addary[5] = new Array(0,0,-1); //red
addary[6] = new Array(255,1,1);
clrary = new Array(360);
for(i = 0; i < 6; i++)
for(j = 0; j < 60; j++) {
clrary[60 * i + j] = new Array(3);
for(k = 0; k < 3; k++) {
clrary[60 * i + j][k] = addary[6][k];
addary[6][k] += (addary[i][k] * 4);
}
}
function capture() {
if(document.layers) {
layobj = document.layers['wheel'];
layobj.document.captureEvents(Event.MOUSEMOVE);
layobj.document.onmousemove = moved;
}
else {
layobj = document.all["wheel"];
layobj.onmousemove = moved;
}
}
function moved(e) {
y = 4 * ((document.layers)?e.layerX:event.offsetX);
x = 4 * ((document.layers)?e.layerY:event.offsetY);
sx = x - 512;
sy = y - 512;
qx = (sx < 0)?0:1;
qy = (sy < 0)?0:1;
q = 2 * qy + qx;
quad = new Array(-180,360,180,0);
xa = Math.abs(sx);
ya = Math.abs(sy);
d = ya * 45 / xa;
if(ya > xa) d = 90 - (xa * 45 / ya);
deg = Math.floor(Math.abs(quad[q] - d));
n = 0;
sx = Math.abs(x - 512);
sy = Math.abs(y - 512);
r = Math.sqrt((sx * sx) + (sy * sy));
if(x == 512 & y == 512) {
c = "000000";
}
else {
for(i = 0; i < 3; i++) {
r2 = clrary[deg][i] * r / 256;
if(r > 256) r2 += Math.floor(r - 256);
if(r2 > 255) r2 = 255;
n = 256 * n + Math.floor(r2);
}
c = n.toString(16);
while(c.length < 6) c = "0" + c;
}
if(document.layers) {
document.layers["wheel"].document.f.t.value = "#" + c;
document.layers["wheel"].bgColor = "#" + c;
}
else {
document.all["wheel"].document.f.t.value = "#" + c;
document.all["wheel"].style.backgroundColor = "#" + c;
}
return false;
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->

<BODY onLoad="capture()">

<!-- STEP THREE: Copy this code into the BODY of your HTML document -->

<div id=wheel style="position:absolute; visibility:visible; top:40px; left:120px;">
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td>
<img src="colorwheel.jpg" width=256 height=256 border=0>
</td>
</tr>
<tr>
<td align="center">
<br>
<form name="f">
<input type="text" name="t" size=27>
</form>
</td>
</tr>
</table>
</div>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 3.15 KB -->

nnanh01
20-05-2009, 17:33
Xin cậu 1 chàu cafe tớ viết lại cho! hehe

shpy
20-05-2009, 18:20
Cafe là chuyện nhỏ. Kết bạn mới là chuyện lớn ! Code là chuyện phụ (vì mình không phải làm IT, thích vọc ngoái thôi). Mình còn đang điên đầu vụ tìm màu gần giống đây này.

Hổm giờ mỗi người chỉ cho 1 chút nên làm được cái này nè

http://www.sonnuoc.com/colorworld.php

nnanh01
20-05-2009, 18:24
Code cho phần FF đã xong nhưng mà chưa up lên đc (chờ cafe mà - kakakaka). Giờ về đã

Hẹn địa điểm và thời gian uống cafe rùi mai tui up lên cho. hehe

[=========> Bổ sung bài viết <=========]



<!-- THREE STEPS TO INSTALL HEXADECIMAL COLOR WHEEL:

1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag
3. Put the last coding into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: D10n (biab@iinet.net.au) -->
<!-- Web Site: http://www.iinet.net.au/~biab -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
addary = new Array(); //red
addary[0] = new Array(0,1,0); //red green
addary[1] = new Array(-1,0,0); //green
addary[2] = new Array(0,0,1); //green blue
addary[3] = new Array(0,-1,0); //blue
addary[4] = new Array(1,0,0); //red blue
addary[5] = new Array(0,0,-1); //red
addary[6] = new Array(255,1,1);
clrary = new Array(360);

var moz=(document.getElementById&&!document.all);

for(i = 0; i < 6; i++)
for(j = 0; j < 60; j++)
{
clrary[60 * i + j] = new Array(3);
for(k = 0; k < 3; k++) {
clrary[60 * i + j][k] = addary[6][k];
addary[6][k] += (addary[i][k] * 4);
}
}
function capture() {
if(document.layers) {
layobj = document.layers['wheel'];
layobj.document.captureEvents(Event.MOUSEMOVE);
layobj.document.onmousemove = moved;
}
else if (document.all)
{
layobj = document.all["wheel"];
layobj.onmousemove = moved;
}
else if (document.getElementById)
{
window.document.getElementById("wheel").onmousemove = moved;
}
}

function moved(e)
{
if (document.layers) {
x = 4 * e.layerY;
y = 4 * e.layerX;
}

else if (document.all) {
x = 4 * event.offsetY;
y = 4 * event.offsetX;
}

else if (document.getElementById) {
x = 4 * (e.pageY - document.getElementById("wheel").offsetLeft);
y = 4 * (e.pageX - document.getElementById("wheel").offsetTop);
}


sx = x - 512;
sy = y - 512;
qx = (sx < 0)?0:1;
qy = (sy < 0)?0:1;
q = 2 * qy + qx;
quad = new Array(-180,360,180,0);
xa = Math.abs(sx);
ya = Math.abs(sy);
d = ya * 45 / xa;

if(ya > xa)
d = 90 - (xa * 45 / ya);

deg = Math.floor(Math.abs(quad[q] - d));
n = 0;
sx = Math.abs(x - 512);
sy = Math.abs(y - 512);
r = Math.sqrt((sx * sx) + (sy * sy));
if(x == 512 & y == 512)
{
c = "000000";
}
else
{
for(i = 0; i < 3; i++)
{
r2 = clrary[deg][i] * r / 256;
if(r > 256) r2 += Math.floor(r - 256);
if(r2 > 255) r2 = 255;
n = 256 * n + Math.floor(r2);
}
c = n.toString(16);
while(c.length < 6)
c = "0" + c;
}

if (document.layers) {
c = c.toUpperCase();
document.layers["wheel"].bgColor = "#" + c;
document.layers["wheel"].document.f.t.value = "#" + c;

} else if (document.all) {
c = c.toUpperCase();
document.all["wheel"].style.backgroundColor = "#" + c;
document.all["wheel"].document.f.t.value = "#" + c;

} else if (document.getElementById) {
c = c.toUpperCase();
document.getElementById("wheel").style.backgroundColor = "#" + c;
document.f.t.value = "#" + c;

}



return false;
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->

<BODY onLoad="capture()">

<!-- STEP THREE: Copy this code into the BODY of your HTML document -->

<div id=wheel style="position:absolute; visibility:visible; top:40px; left:120px;">
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td>
<img src="colorwheel.jpg" width=256 height=256 border=0>
</td>
</tr>
<tr>
<td align="center">
<br>
<form name="f">
<input id='innerValue' type="text" name="t" size=27>
</form>
</td>
</tr>
</table>
</div>
<!-- Script Size: 3.15 KB -->


Bên FF tính lại cái vùng sự kiện chuột. chưa có chính xác.

hehe....

shpy
23-05-2009, 09:07
Oh, hổm giờ bận quá giờ mới quay vào. Thank bạn. Không cần có code hay không, mình sẽ mời bạn 1 chầu cafe nha. Nhưng chắc qua tuần sau.

nnanh01
26-05-2009, 09:03
Nói phải giữ lời! kaka