On 3 Feb., 18:57, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de>
wrote:
Quote:
Ralph 'rkhb' Bauer wrote:
enzinger... (AT) googlemail (DOT) com schrieb:
els.width = ""+ w +"px"; // Fehler laut IE
els.height = ""+ h +"px"; // Fehler laut IE
Trickreich, trickreich ... vielleicht zu trickreich. Wie wäre es denn mit:
els.width = String(w) + 'px';
els.height = String(h) + 'px';
UUOS.
els.width = w + 'px';
els.height = h + 'px';
Der Fehler liegt aber mit an Sicherheit grenzender Wahrscheinlichkeit nicht
an der überflüssigen Konkatenation noch an den anderen Stringbegrenzern,
sondern am Wert von `w' und `h'. Möglicherweise hat der OP auch ein `+'
zuviel geschrieben und w + +"px" == w + "NaN" erzeugt. |
Stimmt auch.
Ich hab auf der Doku von Thomas etwas nachgelesen und der Code läuft
bereits ohne Fehler ;-)
Hier der code:
/**
* JavaScript
*
* @Author Enzinger Thomas
* @Version 1.0
*
*/
/**
* Bild im Browserfenster vergrössern
*
* <div id="expandImageToBrowserSize">
* <table id="tableexpandImageToBrowserSize">
* <tr>
* <td class="expandImageToBrowserSize1">
* <img src="" alt="" id="imgIdexpandImageToBrowserSize"
onmouseover="this.style.cursor = 'pointer'"
onmouseoout="this.style.cursor = 'auto'"
onclick="closeImageToBrowserSize()" />
* </td>
* </tr>
*
* <tr>
* <td class="expandImageToBrowserSize2">
* <a href="javascript
:closeImageToBrowserSize()"
id="aIdexpandImageToBrowserSize" alt="Fenster schliessen"
class="expandImageToBrowserSize" onmouseover="this.style.cursor =
'pointer'" onmouseout="this.style.cursor = 'auto'"
onclick="closeImageToBrowserSize()">Fenster schliessen</a>
* </td>
* </tr>
* </table>
* </div>
*
* ################################################## ############
* ################################################## ############
*
* Akktivieren mit:
* expandImageToBrowserSize(imageURL, altInfo);
*
* Init.:
* initexpandImageToBrowserSize();
*
*/
var divIdexpandImageToBrowserSize = "expandImageToBrowserSize";
var imgIdexpandImageToBrowserSize = "imgIdexpandImageToBrowserSize";
var aIdexpandImageToBrowserSize = "aIdexpandImageToBrowserSize";
var tableexpandImageToBrowserSize = "tableexpandImageToBrowserSize";
var statusexpandImageToBrowserSize = false;
var randexpandImageToBrowserSize = 100;
function expandImageToBrowserSize(imageURL, altInfo) {
// Bild laden
im = new Image();
im.src = imageURL;
im.alt = altInfo;
// Eingaben sperren
el = document.getElementById(divIdexpandImageToBrowserS ize);
els = el.style;
h = parseInt(window.innerHeight);
w = parseInt(window.innerWidth);
// IE
if(navigator.appVersion.indexOf("MSIE") > -1) {
w = parseInt(screen.availWidth);
h = parseInt(screen.availHeight) - 200;
}
els.position = "fixed";
els.left = "0px";
els.top = "0px";
els.width = ""+ parseInt(screen.width) +"px";
els.height = ""+ parseInt(screen.height) +"px";
els.visibility = "visible";
pic = document.getElementById(imgIdexpandImageToBrowserS ize);
pic.src = im.src;
pic.style.width = ""+ parseInt(im.width) +"px";
pic.style.height = ""+ parseInt(im.height) +"px";
pic.alt = altInfo;
statusexpandImageToBrowserSize = true;
setexpandImageToBrowserSizePos();
im = null;
}
function closeImageToBrowserSize() {
pic = document.getElementById(imgIdexpandImageToBrowserS ize);
pic.src = "";
pic.alt = "";
statusexpandImageToBrowserSize = false;
setexpandImageToBrowserSizePos();
}
function setexpandImageToBrowserSizePos() {
el = document.getElementById(divIdexpandImageToBrowserS ize);
els = el.style;
im = document.getElementById(imgIdexpandImageToBrowserS ize);
ims = im.style;
a = document.getElementById(aIdexpandImageToBrowserSiz e);
as = a.style;
table = document.getElementById(tableexpandImageToBrowserS ize);
tables = table.style;
h = parseInt(window.innerHeight);
w = parseInt(window.innerWidth);
// IE
if(navigator.appVersion.indexOf("MSIE") > -1) {
w = parseInt(screen.availWidth);
h = parseInt(screen.availHeight) - 200;
}
//alert("Browserfenster: "+w+" x "+h);
pich = parseInt(im.height);
picw = parseInt(im.width);
r = picw/pich;
if(statusexpandImageToBrowserSize == true) {
// CSS-Eigenschaften setzen
els.position = "fixed";
tables.position = "fixed";
els.left = "0px";
els.top = "0px";
els.width = ""+ parseInt(screen.width) +"px";
els.height = ""+ parseInt(screen.height) +"px";
// Bild ins Fenster einpassen
picw2 = 0;
pich2 = 0;
//alert(picw+"x"+pich+"\n"+picw2+"x"+pich2+"\n"+im.w idth
+"x"+im.height+"\n\nZuschneiden 1 (width): "+ picw +">"+(w -
randexpandImageToBrowserSize));
if( picw > (w - randexpandImageToBrowserSize) ) {
picw2 = w - randexpandImageToBrowserSize;
pich2 = Math.round(picw2/r);
}
//alert(picw+"x"+pich+"\n"+picw2+"x"+pich2+"\n"+im.w idth
+"x"+im.height+"\n\nZuschneiden 1 (width): "+ picw +">"+(w -
randexpandImageToBrowserSize)+"\nZuschneiden 2 (height): "+pich+">"+(h
- randexpandImageToBrowserSize)+" && "+pich2+"=="+0+" || "+pich2+" > "+
(h - randexpandImageToBrowserSize));
if( pich > (h - randexpandImageToBrowserSize) && pich2 == 0 || pich2
Quote:
(h - randexpandImageToBrowserSize) ) {
pich2 = h - randexpandImageToBrowserSize;
|
picw2 = Math.round(pich2*r);
}
//alert(picw+"x"+pich+"\n"+picw2+"x"+pich2+"\n"+im.w idth
+"x"+im.height);
if(picw2 > 0 || pich2 > 0) {
picw = picw2;
pich = pich2;
r = picw/pich;
}
ims.width = ""+ picw +"px";
ims.height = ""+ pich +"px";
//alert(picw+"x"+pich+"\n"+picw2+"x"+pich2+"\n"+im.w idth
+"x"+im.height);
//alert("ims.width: "+ ims.width +"px\nims.height: "+ ims.height +"px
\nim.width: "+ im.width +"px\nim.height: "+ im.height +"px\n");
//alert("w: "+ w +"px\nh: "+ h +"px\npicw"+ picw +"px\npich"+ pich
+"px\n");
//alert("w: "+ w +"px\nh: "+ h +"px\npicw"+ picw +"px\npich"+ pich
+"px\n");
//alert("tables.left: "+ ((w - picw) /2) +"px\ntables.top: "+ ((h -
pich - 20) /2 ) +"px");
//alert("tables.left: "+ Math.round((w - picw) /2) +"px\ntables.top:
"+ Math.round((h - pich - 20) /2 ) +"px");
tables.left = ""+ Math.round((w - picw) /2) +"px";
tables.top = ""+ Math.round((h - pich - 20) /2 ) +"px";
//alert("Position: "+Math.round((w - picw) /2)+" x "+Math.round((h -
pich - 20) /2 )+"\nIst:"+tables.left+" x "+tables.top);
els.visibility = "visible";
tables.visibility = "visible";
ims.visibility = "visible";
as.visibility = "visible";
} else {
// CSS-Eigenschaften setzen
els.visibility = "hidden";
tables.visibility = "hidden";
ims.visibility = "hidden";
as.visibility = "hidden";
els.position = "absolute";
tables.position = "static";
els.top = "0px";
els.left = "-100000px";
els.width = "1px";
els.height = "1px";
im.src = "";
im.alt = "";
ims.width = "";
ims.height = "";
tables.left = "";
tables.top = "";
}
}
function initexpandImageToBrowserSize() {
closeImageToBrowserSize();
}
/**
* ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++
+++++++++++++++++++++++++++++++
*
************************************************** *************************************************
*
* Ende "Bild im Browserfenster vergrössern
*
*
************************************************** *************************************************
* ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++
+++++++++++++++++++++++++++++++
*/