Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
<style type="text/css">
.default {
width: 300px;
height: 200px;
background: #f00;
border: 3px solid #00f;
}
.over {
background: #00f;
border: 5px dashed #0f0;
width: 500px;
height: 300px;
}
</style>
<script type="text/javascript">
// <![CDATA[
function StringUtils() {}
StringUtils.trim = function(str, chars)
{
return StringUtils.ltrim(StringUtils.rtrim(str, chars), chars);
}
StringUtils.ltrim = function(str, chars)
{
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
StringUtils.rtrim = function(str, chars)
{
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function CssHelper() {}
CssHelper.hasClass = function(node, cl)
{
var ret = false;
var classes = StringUtils.trim(node.className).split(' ');
for (var i = 0; i < classes.length; i++) {
if (cl == classes[i]) {
ret = true;
}
}
return ret;
}
CssHelper.addClass = function(node, cl)
{
if (!CssHelper.hasClass(node, cl)) {
node.className += ' ' + cl;
}
}
CssHelper.removeClass = function(node, cl)
{
var classes = StringUtils.trim(node.className).split(' ');
var newClasses = '';
for (j = 0; j < classes.length; j++) {
if (cl != classes[j]) {
newClasses += classes[j] + ' ';
}
}
node.className = newClasses;
}
window.onload = function()
{
var test = document.getElementById('test');
test.onmouseover = function()
{
CssHelper.addClass(this, 'over');
}
test.onmouseout = function()
{
CssHelper.removeClass(this, 'over');
}
}
// ]]>
</script>
<div id="test" class="default"></div>
Ich würde es über das Hinzufügen und Entfernen von CSS-Klassen regeln. Von der Idee her so (nur im Firefox getestet, Verbesserungen willkommen -- in jQuery und Co. ist sowas sicher bereits integriert):
HTML:<style type="text/css"> .default { width: 300px; height: 200px; background: #f00; border: 3px solid #00f; } .over { background: #00f; border: 5px dashed #0f0; width: 500px; height: 300px; } </style> <script type="text/javascript"> // <![CDATA[ function StringUtils() {} StringUtils.trim = function(str, chars) { return StringUtils.ltrim(StringUtils.rtrim(str, chars), chars); } StringUtils.ltrim = function(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } StringUtils.rtrim = function(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } HTMLElement.prototype.hasClass = function(cl) { var ret = false; var classes = StringUtils.trim(this.className).split(' '); for (var i = 0; i < classes.length; i++) { if (cl == classes[i]) { ret = true; } } return ret; } HTMLElement.prototype.addClass = function(cl) { if (!this.hasClass(cl)) { this.className += ' ' + cl; } } HTMLElement.prototype.removeClass = function(cl) { var classes = StringUtils.trim(this.className).split(' '); var newClasses = ''; for (j = 0; j < classes.length; j++) { if (cl != classes[j]) { newClasses += classes[j] + ' '; } } this.className = newClasses; } window.onload = function() { var test = document.getElementById('test'); test.onmouseover = function() { this.addClass('over'); } test.onmouseout = function() { this.removeClass('over'); } } // ]]> </script> <div id="test" class="default"></div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>demo</title>
<style type="text/css">
/* <![CDATA[ */
#test {
width: 300px;
height: 200px;
background: #f00;
border: 3px solid #00f;
}
/* ]]> */
</style>
<script type="text/javascript">
// <![CDATA[
function CssHelper() {};
CssHelper.backupStyles = function(node)
{
node.styleDummy = document.createElement('div');
for (var k in node.style) {
try {
eval("node.styleDummy.style." + k + " = node.style." + k + ";");
} catch(e) {
// For IE's "font" property
}
}
}
CssHelper.restoreStyles = function(node)
{
// Nothing to restore
if (node.styleDummy == null) return;
for (var k in node.styleDummy.style) {
try {
eval("node.style." + k + " = node.styleDummy.style." + k + ";");
} catch (e) {
// Do nothing
}
}
}
window.onload = function()
{
document.getElementById('test').onmouseover = function()
{
CssHelper.backupStyles(this);
this.style.backgroundColor = '#fff';
this.style.borderColor = '#0f0';
}
document.getElementById('test').onmouseout = function()
{
CssHelper.restoreStyles(this);
}
}
// ]]>
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
Leute ich habe das Problem, dass beim Fahren auf den Eingabefeld anstatt der Cursor die Hand angezeigt wird. Weiss jemand wie ich das Problem beheben kann?
CSS fände ich schlauer:@Speedy: Nein, ich habe doch eindeutig geschrieben onmouseover und onmouseout. Die Funktion musss mit JavaScript erfüllt werden. Es ist ein Eingabefeld.
<input type="text" maxlength="240" name="eingabe" size="50" onmouseover="this.style.borderColor='#000000'" onmouseout="this.style.borderColor='#ffffff'" onselect="this.style.color='#000000'" />
Anstatt onmouseout="this.style.borderColor='#ffffff'" möchte ich die Ausgangslage (Wie vor onmouseover)... onmouseout="....'"?
.input {border-color:#fff;}
.input:hover {border-color:#000;}
<input onmouseover="this.style.borderColor='#000000'"
onmouseout="this.style.borderColor=''" />
struppi schrieb:Code:.input {border-color:#fff;} .input:hover {border-color:#000;}