In diesem Artikel wird die Methode von JS beschrieben, um eine Bildschwimmwirkung zu erzielen. Teilen Sie es für Ihre Referenz. Die spezifische Analyse ist wie folgt:
Beschreibung: Wenn Sie die Webseite öffnen, sehen Sie Bilder, die ständig schweben, klicken, um eine Verbindung zu anderen Seiten herzustellen. Es wird einen Schlüsseleffekt haben!
Kopieren Sie den Code wie folgt: <html>
<kopf>
<meta http-äquiv = "content-type" content = "text/html; charset = utf-8">
<title> test </title>
<style type = "text/css">
#ALL {Breite: 100%; Höhe: 3000px;}
</style>
</head>
<body>
<div id = "all">
<div id = "img" style = "Position: absolut; Z-Index: 99;">
<a href = "#" target = "_ leer"> <img src = "Bilder/opvti.jpg" style = "cursor: pointer;" style = "Cursor: Zeiger;" /> </a>
<script Language = "JavaScript">
<!-Beginnen Sie
var xpos = document.body.clientwidth - 20;
var ypos = document.body.clientHeight / 2;
var Schritt = 1;
var delay = 10;
var Höhe = 0;
var Hoffset = 0;
var woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var intervall;
img.style.top = ypos;
Funktion Changepos () {
width = document.body.clientwidth;
Höhe = document.body.clientHeight;
Hoffset = img.offseteight;
Woffset = img.offsetwidth;
img.style.left = xpos + document.body.scrollleft;
img.style.top = ypos + document.body.scrolltop;
if (yon) {
ypos = ypos + Schritt;
} anders {
ypos = ypos - Schritt;
}
if (ypos <0) {
yon = 1;
ypos = 0;
}
if (ypos> = (Höhe - Hoffset)) {
yon = 0;
ypos = (Höhe - Hoffset);
}
if (xon) {
XPOS = XPOS + STEP;
} anders {
xpos = xpos - Schritt;
}
if (xpos <0) {
xon = 1;
xpos = 0;
}
if (xpos> = (width - woffset)) {
xon = 0;
xpos = (width - woffset);
}
}
Funktion start () {
Img.visibility = "sichtbar";
Interval = setInterval ('ChangePos ()', Delay);
}
Funktion pause_resume () {
if (pause) {
ClearInterval (Intervall);
pause = falsch;
} anders {
Interval = setInterval ('ChangePos ()', Delay);
pause = wahr;
}
}
Start();
// Ende ->
</script>
</div>
</div>
</body>
</html>
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.