I am working on implementing a gallery into my website with categories that collapse/expand the set of images within those categories.
i figured out mostly everything i need except i can’t get the BUTTONS to behave the way that I want.
I’m working with the following images:
arrow1:
arrow2:
arrow3:
in general, I want “arrow1” to change to “arrow2” whenever you hover a mouse over it, and back to “arrow1” when the mouse is moves away. (which is simple by itself)
the complicated part that I can’t figure out, is what happens when you CLICK the button. I want the image to change to “arrow3” when it is clicked (because the content expands), and to STAY at that image until it’s clicked again, at which point it should behave as what I started with. The problem is, I can get the arrow to change on click no problem, but once the mouse is moved away, the “onMouseOut” effect changes it back to “arrow1”.
this is the code I’m working with, hope someone can help
mmm, not exactly what I was looking for, I don’t need the menu to be written with the script for the arrows, I just want the mouse over and on click effects to work for the button alone, nothing else. So, just the button, and the functions
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Arrow Menu</title>
<style type ='text/css'>
#arrows {
width: 9px;
height: 9px;
border: 0;
background: transparent url('arrows.png') center left no-repeat;
}
/* Mouse over handled here */
#arrows:hover {
background-position: top left;
}
/* Style for 'clicked' class to show clicked arrow */
#arrows:active, #arrows.clicked {
background-position: bottom left;
}
#imageSet {
margin: 20px 0 0 -9999px;
width: 100px;
height: 100px;
color: #ccc;
background: #222;
border: 1px solid black;
}
/* Style for 'show' class to show imageSet */
#imageSet.show {
margin-left: 0px;
}
</style>
</head>
<body>
<button id = 'arrows'></button>
<div id="imageSet">imgset1</div>
<script type = 'text/javascript'>
var toggle = function(el, className) {
var classMatch = new RegExp('(\\\\s?' + className + ')\\\\b'),
classToMatch = el.className;
el.className = (classMatch.test(classToMatch))
? classToMatch.replace(classMatch, '')
: classToMatch + ' ' + className;
};
// This bit is for the button
var toggleButton = 'clicked',
button = document.getElementById('arrows'),
// This bit is for the imageSet div element
toggleImageSet = 'show',
imageSet = document.getElementById('imageSet');
button.onclick = function(){
toggle(button, toggleButton); // first toggle the 'clicked' class on the button
toggle(imageSet, toggleImageSet); // second toggle the 'show' class on the imageSet
};
</script>
</body>
</html>