How can I add if condition

This question already has an answer here:

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

  • You can use the .width method in jquery to determine the width of the window and just change the object properties accordingly.

    You can use it like this:

    <script>
    if ($( window ).width() < 600) {
      $("#zoom_01").elevateZoom({
      gallery:'gallery_01',
      zoomEnabled: false,
      cursor: 'pointer',
      galleryActiveClass: 'active'
    } else {
      $("#zoom_01").elevateZoom({
        gallery:'gallery_01',
        zoomEnabled: true,
        cursor: 'pointer',
        galleryActiveClass: 'active'
    }
    </script>
    

    A more readable approach (at least for me):

    <script>
        $("#zoom_01").elevateZoom({
            gallery:'gallery_01',
            zoomEnabled: ( $(window).width() >= 600 ),
            cursor: 'pointer',
            galleryActiveClass: 'active'
        });
    </script>
    

    but to be fair: read a javascript tutorial or 2 and you could've figured this out yourself.

    链接地址: http://www.djcxy.com/p/84066.html

    上一篇: 网页部分仅可见于手机

    下一篇: 如何添加条件