Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCarl-Kaspar Puhm
Front End Web Development Techdegree Student 8,692 PointsI need to make Jquery plugin work with a media query
On the website i am developing i use a jQuery image zoom plugin, but i need to make it work only when viewport with is over 940px.
so this is my js code:
$(window).resize(function(){
if ($(window).width() >= 940){
$("#zoom").elevateZoom({
zoomType : "inner",
cursor: "crosshair"
});
}
});
It is working, but only after i resize my browser window. What could be the problem?
1 Answer
Steven Parker
231,271 PointsDo you need it to run when the window loads and when it is resized? You might define the function separately and both call it once immediately and also establish it as the resize event handler.
Carl-Kaspar Puhm
Front End Web Development Techdegree Student 8,692 PointsCarl-Kaspar Puhm
Front End Web Development Techdegree Student 8,692 PointsNever mind... without the resize function everything works fine!