0

I have a slide where I want to show photos specific for each device. iPhone, iPad, Desktop.

I would like to use something like this to filter each out. Obviously display:none isn't going to work since it's JavaScript, but this is just a general idea of how it should work:

<style type="text/css">
@media only screen and (min-width: 800px) {
    #slide-desktop{display:block;}
    #slide-ipad{display:none;}
    #slide-iphone{display:none;}
}
@media only screen and (min-width: 481px) and (max-width: 799px) {
    #slide-desktop{display:none;}
    #slide-ipad{display:block;}
    #slide-iphone{display:none;}
}
@media only screen and (max-width: 480px) {
    #slide-desktop{display:none;}
    #slide-ipad{display:none;}
    #slide-iphone{display:block;}
}
</style>
<div id="slide-desktop">
    <script>
        $.vegas('slideshow', {
        delay:6000,
        backgrounds:[
        { src:'images/slide/desktop.jpg', fade:600 },
        ]
        })('overlay');
    </script>
</div>
<div id="slide-ipad">
    <script>
        $.vegas('slideshow', {
        delay:6000,
        backgrounds:[
        { src:'images/slide/ipad.jpg', fade:600 },
        ]
        })('overlay');
    </script>
</div>
<div id="slide-iphone">
    <script>
        $.vegas('slideshow', {
        delay:6000,
        backgrounds:[
        { src:'images/slide/iphone.jpg', fade:600 },
        ]
        })('overlay');
    </script>
</div>
2
  • 1
    What do you mean by display:none is Javascript ? It's a CSS property. Commented Nov 1, 2013 at 21:48
  • How the header is actually related to the question? Commented Nov 1, 2013 at 21:59

2 Answers 2

1

If you want to run different scripts based on a media query you can use enquire.js

enquire.js is a lightweight, pure JavaScript library for responding to CSS media queries.

So, you no need to put anything in a style at all.

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

Comments

1

If you want to check by the device width you can use simple javascript like this

   if(window.innerWidth >= 800)
   {
     alert('desktop?');
   }
   else if(window.innerWidth >= 481 && window.innerWidth < 799)
   {
     alert('ipad?');
   }
   else if(window.innerWidth < 480)
   {
    alert('iphone?');
   }

But I would not go for this technique. Check out

What is the best way to detect a mobile device in jQuery?

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.