0

I have a hover state that I want to use, but only if the opacity is not .65, this is what I have but it's not quite working, not sure exactly how to change it. Thanks in advance for any help.

$('.info_btn').hover(
  var jthis = this;
  if($('.info_btn').css('opacity') == 0.65) { }
  else {
    function() {
        $(jthis).css({
              "opacity": "0.7",
              "-moz-opacity": "0.7",
              "filter": "alpha(opacity = 70)"
        });
    }, function() {
        $(jthis).css({
              "opacity": "0.2",
              "-moz-opacity": "0.2",
              "filter": "alpha(opacity = 20)"
        });
    }
  }
); 
2

2 Answers 2

2

This one only binds the events to the only .info_btn elements that have opaticy == 0.65. Useful in case you've lots of .info_btn elements

        $('.info_btn').filter(function () {
           return parseFloat($(this).css('opacity')) == 0.65
        }).on({
              mouseover: function () {
                 $(this).css({
                    "opacity": "0.7",
                    "-moz-opacity": "0.7",
                    "filter": "alpha(opacity = 70)"
                 });
              },
              mouseout: function () {
                 $(this).css({
                    "opacity": "0.2",
                    "-moz-opacity": "0.2",
                    "filter": "alpha(opacity = 20)"
                 });
              }
           });

It let's you maintain the condition opacity == 0.65 in one place, doesn't attach events to extra .info_btn elements.

Sign up to request clarification or add additional context in comments.

Comments

1
$('.info_btn').mouseover(function() {
     if($(this).css('opacity') == 0.65) { }
});

This is all you need for what you described in your question.

mouseover and hover are kinda the same thing
http://api.jquery.com/mouseover/
http://api.jquery.com/hover/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.