daveoffy Posted March 10, 2009 Share Posted March 10, 2009 I have a set of buttons, all in a div. The buttons are transparent over the div, so the div has the background I want to switch from. button and buttonhover are the divs. it is like this so far <div class="button"><img src="image.png"><img src="image1.png"></div> I want so when I hover that the class changes. Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/ Share on other sites More sharing options...
darkfreaks Posted March 10, 2009 Share Posted March 10, 2009 http://techpatterns.com/downloads/examples/class-switcher.htm this what you after ??? Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781583 Share on other sites More sharing options...
daveoffy Posted March 10, 2009 Author Share Posted March 10, 2009 great, I will get to work on that code soon. Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781586 Share on other sites More sharing options...
daveoffy Posted March 10, 2009 Author Share Posted March 10, 2009 *could not modify* Ok so, When I have an image in that div of the class, when I am over the image it wont switch. <div class="buttonbg"> <img src="../skin/images/editor.png" width="15px" height="15px" onclick="addText('editor', '<html>\n<head>\n<title></title>\n</head>\n<body>\n\n</body>\n</html>');"> </div> Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781611 Share on other sites More sharing options...
darkfreaks Posted March 11, 2009 Share Posted March 11, 2009 can you paste the function ??? Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781744 Share on other sites More sharing options...
daveoffy Posted March 11, 2009 Author Share Posted March 11, 2009 the javascript <script type="text/javascript"> var classname = 'buttonbg'; var classname1 = 'buttonbg'; var classname2 = 'hoverbuttonbg'; var feature = 'single'; function getElementsByClassName(needle) { var my_array = document.getElementsByTagName("*"); var retvalue = new Array(); var i; var j; for (i=0,j=0;i<my_array.length;i++) { var c = " " + my_array[i].className + " "; if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i]; } return retvalue; } function toggle() { var divs = getElementsByClassName(classname) for(i=0; i <divs.length;i++) { if(divs[i].className == classname1) { divs[i].className = classname2; classname = classname2; } else { divs[i].className = classname1; classname = classname1; } } } function rollon(e) { var srcId, srcElement, targetElement; if (window.event) e = window.event; srcElement = ( e.srcElement ) ? e.srcElement : e.target; if ( srcElement.className == classname1 ) { if ( feature == 'all' ) { toggle(); } else if ( feature == 'single' ) { srcElement.className = classname2; classname = classname2; } } } function rolloff(e) { var srcId, srcElement, targetElement; if (window.event) e = window.event; srcElement = ( e.srcElement ) ? e.srcElement : e.target; if ( srcElement.className == classname2 ) { if ( feature == 'all' ) { toggle(); } else if ( feature == 'single' ) { srcElement.className = classname1; classname = classname1; } } } document.onmouseover = rollon; document.onmouseout = rolloff; </script> Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781749 Share on other sites More sharing options...
darkfreaks Posted March 11, 2009 Share Posted March 11, 2009 use fulll stop character notations not [] also you are missing a semi colon on line 22 Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781767 Share on other sites More sharing options...
daveoffy Posted March 11, 2009 Author Share Posted March 11, 2009 what is full stop character notations Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781770 Share on other sites More sharing options...
darkfreaks Posted March 11, 2009 Share Posted March 11, 2009 Dot-notation is most commonly used in JS to access properties of objects, which means that the property name is given after a full stop character. For example: Given: <form id="myForm" action="/"> <div><input name="foo"></div> </form> We can say: var myForm = document.getElementById("myForm"); var input = myForm.foo; Here we call the getElementById property of the document object as a function, and then we take the foo property of the form (which is the input with the name "foo"). Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781772 Share on other sites More sharing options...
daveoffy Posted March 11, 2009 Author Share Posted March 11, 2009 That doesn't fix my problem. I am trying to get it so when the image is hovered also, it still changes the class. Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781775 Share on other sites More sharing options...
darkfreaks Posted March 11, 2009 Share Posted March 11, 2009 also some of your if statements are missing curly brackets {} var classname = 'buttonbg'; var classname1 = 'buttonbg'; var classname2 = 'hoverbuttonbg'; var feature = 'single'; function getElementsByClassName(needle) { var my_array = document.getElementsByTagName("*"); var retvalue = new Array(); var i; var j; for (i=0,j=0;i<my_array.length;i++) { var c = " " + my_array[i].className + " "; if (c.indexOf(" " + needle + " ") != -1)retvalue[j++] = my_array[i]; } return retvalue; } function toggle() { var divs = getElementsByClassName(classname); for(i=0; i <divs.length;i++) { if(divs[i].className == classname1) { divs[i].className = classname2; classname = classname2; } else { divs[i].className = classname1; classname = classname1; } } } function rollon(e) { var srcId, srcElement, targetElement; if (window.event) e = window.event; srcElement = ( e.srcElement ) ? e.srcElement : e.target; if ( srcElement.className == classname1 ) { if ( feature == 'all' ) { toggle(); } else if ( feature == 'single' ) { srcElement.className = classname2; classname = classname2; } } } function rolloff(e) { var srcId, srcElement, targetElement; if (window.event) e = window.event; srcElement = ( e.srcElement ) ? e.srcElement : e.target; if ( srcElement.className == classname2 ) { if ( feature == 'all' ) { toggle(); } else if ( feature == 'single' ) { srcElement.className = classname1; classname = classname1; } } } document.onmouseover = rollon; document.onmouseout = rolloff; Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-781851 Share on other sites More sharing options...
daveoffy Posted March 11, 2009 Author Share Posted March 11, 2009 That doesn't fix my first problem. When I go over the image in the div tag, it wont change, but if I go over any other part of that div tag it works fine. Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-782020 Share on other sites More sharing options...
darkfreaks Posted March 12, 2009 Share Posted March 12, 2009 got a working example ??? Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-783214 Share on other sites More sharing options...
daveoffy Posted March 12, 2009 Author Share Posted March 12, 2009 http://webzava.com/editor.php is the page. The buttons on the top of the box, when you hover over the image, it does not change. Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-783396 Share on other sites More sharing options...
darkfreaks Posted March 13, 2009 Share Posted March 13, 2009 only the first image even loads ??? http://bonrouge.com/~imageswitch#n Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-783453 Share on other sites More sharing options...
daveoffy Posted March 13, 2009 Author Share Posted March 13, 2009 I didn't set the other images yet, not until I finish this javascript and get it working. Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-783478 Share on other sites More sharing options...
darkfreaks Posted March 13, 2009 Share Posted March 13, 2009 hope that link is what you need ??? Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-783488 Share on other sites More sharing options...
daveoffy Posted March 13, 2009 Author Share Posted March 13, 2009 Not really. I have the hover working, but when I hover over the image on that page, the class doesn't change. It says the same. I need to make it so everything in the class when hovered it will change the class also. Link to comment https://forums.phpfreaks.com/topic/148837-hover-buttons-background-in-div/#findComment-783490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.