I didn't make it simpler, really, but I did optimize it a bit.

Here only three jQuery objects are created, as opposed to eight in your example.

$(document).ready(function(){
               var $hover = $('#hover');
               var $normal = $('#normal');

                $("#showPic").hover(function() {
                                $hover.removeClass("hidden");
                }, function() {
                                $hover.addClass("hidden");
                })
                .mousedown(function() {
                                $hover.addClass("hidden");
                                $normal.addClass("hidden");
                })
                .mouseup(function() {
                                $normal.removeClass("hidden");
                });
});



--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Jul 25, 2007, at 11:42 PM, Mitchell Waite wrote:

I defy anyone to make this simpler (and work as well)!!!!!



A true 3 state button



http://www.whatbird.com/wwwroot/3statebutton_6.html



(document).ready(function(){



                $("#showPic").hover(function() {

                                $("#hover").removeClass("hidden");

                }, function() {

                                $("#hover").addClass("hidden");

                });



                $("#showPic").mousedown(function() {

                                $("#hover").addClass("hidden");

                                $("#normal").addClass("hidden");

                });



                $("#showPic").mouseup(function() {

                                $("#normal").removeClass("hidden");

                });



});



From: jquery-en@googlegroups.com [mailto:jquery- [EMAIL PROTECTED] On Behalf OfMitchell Waite
Sent: Wednesday, July 25, 2007 7:34 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Toggling an objects visiblty without show and hide



Ok here is the skinny (I think I am getting this down)



http://www.whatbird.com/wwwroot/3statebutton_3.html (uses layers)



$(document).ready(function(){

                $("#showPic").hover(function() {

                                $("#normal").addClass("hidden");

                }, function() {

                                $("#normal").removeClass("hidden");

                });

});



The hover button is under the normal button layer so all we have to do is hide and unhide the normal button.



http://www.whatbird.com/wwwroot/3statebutton_4.html (no layers)



$(document).ready(function(){

                $("#showPic").hover(function() {

                                $("#hover").removeClass("hidden");

                                $("#normal").addClass("hidden");

                }, function() {

                                $("#hover").addClass("hidden");

                                $("#normal").removeClass("hidden");

                });

});



Since both bottons are in the same div they can’t both be on at the same , or you would see them side by side. So you hide and unhide both buttons. More processing but less divs.



Mitch







Reply via email to