jquery - Resetting the .style of an element / reverting to 'initial' without .style overriding -


i have div (.projecttitle) inside of div (.projectcontainer). when screen greater 1000px wide, .projecttitle initialized opacity:0;. when screen less 1000px wide, initialized opacity:1;. see:

@media (min-width: 1000px) {     .projecttitle {         opacity:0;     } } @media (max-width: 1000px) {     .projecttitle {         opacity:1;     } } 

now, if .projectcontainer hovered on while screen wider 1000px, opacity of .projecttitle should animate 1, , 0 when unhovered. however, nothing should happen if hovered on when screen less 1000px; should alway remain @ 1 in case.

i have variable (windowstate) changes depending on width of screen:

less 1000px, windowstate = 3

greater 1000px, windowstate = 2

i have jquery event looks handle hovering, it's job properly:

$(".projectcontainerr").hover(     function(){         if (windowstate != 3){             $('.projecttitle', this).animate({                 opacity:1},100);         }     },     function(){         if(windowstate != 3){             $('.projecttitle', this).animate({                 opacity:"initial"},100);         }     } ); 

the problem

when opacity reset it's value of initial (aka, value defined in media queries) after unhovering, value overridden fact set 1, when hovered onto. "1" value hovering placed element's style, overriding inherited value css 'initial' has returned to.

how prevent value overriding / reset / animate without using element's style?

why don't using css3 transition instead of jquery

@media (min-width: 1000px) {   .projectcontainer:hover .projecttitle{     opacity: 1;     transition: opacity 1s ease-in-out;     -moz-transition: opacity 1s ease-in-out;     -webkit-transition: opacity 1s ease-in-out;   }   .projecttitle {     opacity:0;   } } @media (max-width: 1000px) {   .projecttitle {     opacity:1;    } } 

here demo


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -