1

I have this code which allows me to change the style sheet when the browser is re-sized:

            $(window).resize(function () {
            var width = $(window).width();
            var height = $(window).height();

            if ((width <= 1280) && (height <= 800)) {
                $("link[rel=stylesheet]:not(:first)").attr({ href: "Styles/Home-1024.css" });
            }
            else if ((width > 1280) && (height > 800)) {
                $("link[rel=stylesheet]:not(:first)").attr({ href: "Styles/Home.css" });
            }
        });

and it works fine but i am trying to change the style sheet again when the browser returns to its original size.

JJJ
  • 32,902
  • 20
  • 89
  • 102
Wahtever
  • 3,597
  • 10
  • 44
  • 79
  • I don't quite understand the problem. If your code works, won't it fire both when the browser is resized the first time, *and* when the browser is size back to its original size? – lowerkey Aug 10 '11 at 11:17
  • @Joshua Moore - that's what i thought but it only works on the first resize and never on the second one – Wahtever Aug 10 '11 at 11:19
  • Can you set up an example at jsfiddle.net? – lowerkey Aug 10 '11 at 12:12
  • @Joshua Moore - [here](http://jsfiddle.net/QpnxC/2/) is an example its different that this since i cant add style sheets on jsfiddle – Wahtever Aug 10 '11 at 23:52
  • You should remove the solution from your question and add it as an answer (and accept it if it actually solved your problem). – murgatroid99 Sep 19 '11 at 02:07

3 Answers3

0

You can try:

$(window).live("resize", function(){

});
silverstrike
  • 522
  • 2
  • 7
0

I think part of the problem is that the script fires at each moment of each drag.

You might consider adding a delay so that the event is not repeated so many times.

See this: JavaScript/JQuery: $(window).resize how to fire AFTER the resize is completed?

Community
  • 1
  • 1
Jason Gennaro
  • 34,535
  • 8
  • 65
  • 86
0

i was missing a double greater than so instead of this :

else if ((width > 1280) && (height > 800)) {

i used this and it worked:

else if ((width >> 1280) && (height >> 800)) {
Wahtever
  • 3,597
  • 10
  • 44
  • 79