-1

Is there code that I can apply to Media Queries that will disable an image slider that has jQuery?

I want to disable a slider for mobile because the slider displays somewhere off screen so its not viewable so id like to disable it.

Heres the code: (its sloppy, sorry)

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
<script src="jquery-1.11.1.min.js"></script>
<script src="jquery.cycle.all.js"></script>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<script type="text/javascript">
$('#slider').cycle({ 
    fx:     'scrollHorz', 
    prev:   '#prev', 
    next:   '#next', 
    timeout: 0, 
    rev: false 
});
</script>


<style type="text/css">

#wrapper {
    display: block;
    max-width: 660px;
    max-height: 500px;
    margin: auto;
    position: fixed;
    top: 0%; 
    bottom: 0%; 
    right: 10%;



}
#container {
    display: block;
    float: left;
    height: auto;
    width: 660px;
    overflow: auto;  

}
#prev {
    background-image: url(left%20button.png);

    background-position: center center;
    display: block;
    float: left;
    height: 500px;
    width: 80px;
    position: relative;
    z-index: 99;
    cursor: pointer;

}

#prev:hover {
    background-image: url(left%20button%20grey.png);
}


#next {
    background-image: url(right%20button.png);
    background-position: center center;
    display: block;
    float: right;
    height: 500px;
    width: 80px;
    position: relative;
    z-index: 99;
    cursor: pointer;
}

#next:hover {
    background-image: url(right%20button%20grey.png);
}
#slider {
    display: block;
    height: 500px;
    width: 500px;
    overflow: hidden;
    float: left;
    position: relative;

}
body {
    background-color: #000;
}

/*background image*/
#fsbg  {   

    width: 100%;
    height: auto;
    position: fixed;
    z-index: -100;
    left: 0px;
    top: 0px;
    min-height: 100%;
    min-width: 1040px;
}
#shadow {
    display: block;
    height: 550px;
    width: 550px;
    margin: auto;
    top: 0%;
    bottom: 0%;
    right: 15%;
    position: fixed;
}

/*header nav bar*/
#table {
    background-color: #000;
    margin: 0;
    padding: 0;
    position: fixed;
    left: 0px;
    top: 0px;
    height: 7%;
    z-index: ;
}

/*footer nav bar*/
#table2 {
    background-color: #000;
    margin: 0;
    padding: 10;
    left: 0px;
    bottom: 0px;
    position: absolute ;
    width: 100%;
    height: 5%;
    z-index: 0;
}
textem {
    color: #FFF;
}
.textem2 {
    color: #666;
    text-align: right;
    font-family: "Bebas Neue";
    font-size: 16px;
}


@media screen and (max-width: 500px) {
  #wrapper, #container, #slider {
    width: 100%;
    left: 0px;
    bottom: 0px;
    position: fixed;
  }



  #prev {
      width: 80px;
      height: 200px;
      position: fixed;
      left: 20%;

      top: 65%;
  }

  #next {
      width: 80px;
      height: 200px;
      position: fixed;
      right: 20%;

      top: 65%;

  }

  img {
      width: 100%;
      height: auto;
      margin: auto;


  }
  #shadow {
      opacity: 0;
  }
}

</style>
</head>

<body>
/*header nav bar*/
<table width="100%" border="0" id="table">
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

/*footer nav bar*/
<table width="100%" border="0" id="table2">
  <tr>
    <td class="textem2">Contact</td>
  </tr>
</table>

/*background image*/ 
<img src="eminem.jpg" name="fsbg" width="1409" height="1059" id="fsbg">
<div id="wrapper">
  <div id="container">>
    <div class="controller" id="prev"></div>
    <div id="slider">
    <img src="500x500/Eminem - Marshall Mathers LP 2 HQ 500x500.png" width="500" height="500" alt="MMLP2"> 
    <img src="500x500/Eminem - Bad Guy 2 500x500.png" width="500" height="500" alt="bad guy">
    <img src="500x500/Eminem - Parking Lot 500x500.png" width="500" height="500" alt="parking lot">
    <img src="500x500/Eminem - Rhyme Or Reason 500x500.png" width="500" height="500" alt="rhyme or reason">
    <img src="500x500/Eminem - So Much Better 500x500.png" width="500" height="500" alt="so much better">
    <img src="500x500/Eminem - Survival 500x500.png" width="500" height="500" alt="survival">
    <img src="500x500/Eminem - Legacy 500x500.png" width="500" height="500" alt="legacy">
    <img src="500x500/Eminem - Asshole.png" width="500" height="500" alt="asshole">
    <img src="500x500/Eminem - Berzerk 500x500.png" width="500" height="500" alt="berserk">
    <img src="500x500/Eminem - Rap God 500x500.png" width="500" height="500" alt="rap god">
    <img src="500x500/Eminem - Brainless 2 500x500.png" width="500" height="500" alt="brainless">
    <img src="500x500/Eminem - Stronger Than I Was 500x500.png" width="500" height="500" alt="stronger than i was">
    <img src="500x500/Eminem - The Monster 500x500.png" width="500" height="500" alt="the monster">
    <img src="500x500/Eminem - So Far 500x500.png" width="500" height="500" alt="so far">
    <img src="500x500/Eminem - Love Game 500x500.png" width="500" height="500" alt="so far">
    <img src="500x500/Eminem - Headlights 2 500x500.png" width="500" height="500" alt="headlights">
    <img src="500x500/Eminem - Evil Twin 500x500.png" width="500" height="500" alt="evil twin">
    </div>
    <div class="controller" id="next"></div>
    <div id="shadow">
    <img src=shadow.png" width="550" height="550" alt="">
    </div>
  </div>
</div>
</body>
</html>
Dunne08
  • 143
  • 2
  • 2
  • 10

1 Answers1

0

Expanding on what Jay said, if you don't want to run the scripts, I suggest using something like Modernizr with the Modernizr.touch test (in Extras), then using that with YepNope.js (can be included with modernizr) for conditional loading.

Go to modernizr.com/download, click on Touch Events in Misc, Click Generate, save that as modernizr.js, put in head before any other scripts load

jsFiddle example for seeing markup. Move the css to be external for readability.

HTML:

<!-- loading modernizr script first in HEAD tags -->
<script src="modernizer.js"></script>

<!-- All your HTML Content Here -->

<!-- put scripts before closing body tag -->
<script>
   yepnope({
      test : Modernizr.touch, // Returns true if supports touch events
    yep  : [ // These scripts will run on mobile
        'jquery-1.11.1.min.js', 
        'SpryAssets/SpryMenuBar.js'
      ],
    nope : [ // These scripts will run on desktop
        'jquery-1.11.1.min.js', 
        'SpryAssets/SpryMenuBar.js',
        'jquery.cycle.all.js',
        'domReady.js'
        ]
    });
</script>

Create domReady.js file and move plugin call into it.

// This is your external domReady.js file.
$(document).ready(function() {
    $('#slider').cycle({ 
        fx:     'scrollHorz', 
        prev:   '#prev', 
        next:   '#next', 
        timeout: 0, 
        rev: false 
    });
});

Let me know if none of that makes sense.

this is my code now:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="slider.css" rel="stylesheet" type="text/css" />
<script src="modernizer.js"></script>

</head>

<body>
<body>
<table width="100%" border="0" id="table">
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

<table width="100%" border="0" id="table2">
  <tr>
    <td class="textem2">Contact</td>
  </tr>
</table>


<img src="eminem.jpg" name="fsbg" width="1409" height="1059" id="fsbg">

<div id="wrapper">
  <div id="container">>
    <div class="controller" id="prev"></div>
    <div id="slider">
    <img src="500x500/Eminem - Marshall Mathers LP 2 HQ 500x500.png" width="500" height="500" alt="MMLP2"> 
    <img src="500x500/Eminem - Bad Guy 2 500x500.png" width="500" height="500" alt="bad guy">
    <img src="500x500/Eminem - Parking Lot 500x500.png" width="500" height="500" alt="parking lot">
    <img src="500x500/Eminem - Rhyme Or Reason 500x500.png" width="500" height="500" alt="rhyme or reason">
    <img src="500x500/Eminem - So Much Better 500x500.png" width="500" height="500" alt="so much better">
    <img src="500x500/Eminem - Survival 500x500.png" width="500" height="500" alt="survival">
    <img src="500x500/Eminem - Legacy 500x500.png" width="500" height="500" alt="legacy">
    <img src="500x500/Eminem - Asshole.png" width="500" height="500" alt="asshole">
    <img src="500x500/Eminem - Berzerk 500x500.png" width="500" height="500" alt="berserk">
    <img src="500x500/Eminem - Rap God 500x500.png" width="500" height="500" alt="rap god">
    <img src="500x500/Eminem - Brainless 2 500x500.png" width="500" height="500" alt="brainless">
    <img src="500x500/Eminem - Stronger Than I Was 500x500.png" width="500" height="500" alt="stronger than i was">
    <img src="500x500/Eminem - The Monster 500x500.png" width="500" height="500" alt="the monster">
    <img src="500x500/Eminem - So Far 500x500.png" width="500" height="500" alt="so far">
    <img src="500x500/Eminem - Love Game 500x500.png" width="500" height="500" alt="so far">
    <img src="500x500/Eminem - Headlights 2 500x500.png" width="500" height="500" alt="headlights">
    <img src="500x500/Eminem - Evil Twin 500x500.png" width="500" height="500" alt="evil twin">
    </div>
    <div class="controller" id="next"></div>
    <div id="shadow">
    <img src=shadow.png" width="550" height="550" alt="">
    </div>
  </div>
</div>

<script>
   yepnope({
      test : Modernizr.touch, // Returns true if supports touch events
    yep  : [ // These scripts will run on mobile
        'jquery-1.11.1.min.js', 
        'SpryAssets/SpryMenuBar.js'
      ],
    nope : [ // These scripts will run on desktop
        'jquery-1.11.1.min.js', 
        'SpryAssets/SpryMenuBar.js',
        jquery.cycle.all.js',
        'domready.js'
        ]
    });
</script>

</body>
</html>
Dunne08
  • 143
  • 2
  • 2
  • 10
Christopher Marshall
  • 10,678
  • 10
  • 55
  • 94
  • thanks for your comment, I really dont know much about js code so i dont know how to use something like Modernizr or where to put that code, can you elaborate how i can? this will disable j query in mobile? – Dunne08 May 30 '14 at 19:37
  • Go to http://modernizr.com/download/, click on Touch Events in Misc, Click Generate, save that as modernizr.js, put in head before any other scripts load. I'll edit to show you what it should look like. – Christopher Marshall May 30 '14 at 19:51
  • Edited with instructions on how to set it up. – Christopher Marshall May 30 '14 at 20:00
  • 1
    I'm not saying this isn't a good solution, but won't it also disable the slider for many other touch enabled devices where the screen resolution could be quite large and support the slider (like my 15" touch-enabled laptop)? Also, I might be confused here, but won't you just throw and error when you call the cycle method without having the jquery.cycle.all.js loaded on touch-enabled devices? Is that the idea here? – jme11 May 30 '14 at 20:17
  • You could also use the Modernizer.mq() test for the YepNope parameter. Such as test: Modernizr.mq('(min-width: 569px)'), really it's as versatile as it's conditional. – Christopher Marshall May 30 '14 at 20:47
  • @ChristopherMarshall It makes sense and ive tried that but now the slider doesnt work in deskstop, its not centered and on mobile it shows the slider. what im trying to do is have the slider in deskstop and in mobile have no slider, the images will wont be in any slider just placed on top of each other where you have to scroll down to see them, do you know what i can do to get this? – Dunne08 May 30 '14 at 20:52
  • There's something not set up right then, as it should function exactly as expected per above. – Christopher Marshall May 30 '14 at 20:53
  • Check out Scott Simpsons comment for a simpler solution. – Christopher Marshall May 30 '14 at 20:55
  • i just added my code to your answer above, i have realised that i did not download yepnope.js will that be the problem? – Dunne08 May 30 '14 at 21:15
  • That would definitely be a problem, It should be included by default. Make sure you have the checkbox Modernizer.load checked when creating your modernizr build. Check your console for error messages! – Christopher Marshall May 30 '14 at 22:15