Reputation: 189
Hello guys I have this simple jquery animation
$(window).load(function() {
//Top Header Logo Expand
$("#logo-expand").mouseenter(function() {
$(this).animate({
width: "170px"
}, 300 );
});
$("#logo-expand").mouseleave(function() {
$(this).animate({
width: "56px"
}, 300 );
});
});
Now I want to disable the animation when I am in a phone resolution, how can i do that with jquery media queries, any idea?
Here's my http://jsfiddle.net/MyKnB/5/
thank you in advance
Upvotes: 1
Views: 1257
Reputation: 59
not using media queries as im not sure its possible but I hope this helps JSFiddle
effectivly it checks the window size and then runs the animations or not
$("#logo-expand").mouseenter(function() {
if($(window).width() > 100){
$(this).animate({
width: "170px"
}, 300 );
} else {
$(this).css({'width':"170px"});
}
});
$("#logo-expand").mouseleave(function() {
if($(window).width() > 100){
$(this).animate({
width: "56px"
}, 300 );
} else {
$(this).css({'width':"56px"});
}
});
Upvotes: 0
Reputation: 1065
you can use window.innerWidth
to determine the width of the screen and perform animation only if it is greater than certain width
$(window).load(function() {
if (window.innerWidth > 700){
//Top Header Logo Expand
$("#logo-expand").mouseenter(function() {
$(this).animate({
width: "170px"
}, 300 );
});
$("#logo-expand").mouseleave(function() {
$(this).animate({
width: "56px"
}, 300 );
}
});
});
Upvotes: 2
Reputation: 3656
This worked for me:
if($(window).width() > 320) {
$("#logo-expand").mouseenter(function() {
$(this).animate({
width: "170px"
}, 300 );
});
$("#logo-expand").mouseleave(function() {
$(this).animate({
width: "56px"
}, 300 );
});
}
See here: http://jsfiddle.net/MyKnB/7/
For best results, you'd probably want to throw that into a function and call it on window resize.
Upvotes: 1