Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:23:19+00:00 2026-06-10T21:23:19+00:00

I have a demo here to illustrate my problem. It’s a scrolling image gallery.

  • 0

I have a demo here to illustrate my problem. It’s a scrolling image gallery. When an image is clicked it’s shown bigger – lightbox style.

The hover and click on the images is done with jQuery. I wanted the page to be responsive to work with phone screens. If the browser is resized to 400px approximately the layout changes to one column and scrolls vertically.

When the layout changes I wanted the jQuery to stop – I don’t want the hover and I don’t want the larger image when it’s clicked. How can I stop or change the jQuery when the media query kicks in?

<!DOCTYPE html>
<html>
<head>
    <title>Title of the document</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.4.1/build/cssreset/cssreset-min.css">

    <style type="text/css">
        #header{
        position:fixed;
        margin:20px 0 0 20px;
        }
        #header #logo{
        width:100px;
        height:80px;
        background:red;
        }
        ul#gallery {
        margin:120px 0 0 0;
        float:left;
        height:500px;
        margin-right:-20000px;
        }
        ul#gallery li{
        display:inline;
        }
        ul#gallery li img{
        float:left;
        height:100%;
        }
        #lightbox {
            position:fixed; 
            top:0; 
            left:0; 
            width:100%; 
            height:100%; 
            background:url(overlay.png) repeat; 
            text-align:center;
        }
        #lightbox p {
            text-align:right; 
            color:#fff; 
            margin-right:20px; 
            font-size:12px; 
        }
        #lightbox img {
            box-shadow:0 0 15px #111;
            -webkit-box-shadow:0 0 15px #111;
            -moz-box-shadow:0 0 15px #111;
            max-width:940px;
        }
        #content img{
          height:85%;
          max-width:100%;
        }

        /*--------------------------------------
          Media Query
        ---------------------------------------*/

        @media screen and (max-width: 400px){
            #header #logo{
            height:50px;
            }
            ul#gallery {
            margin:20px 0 0 0;
            width:400px;
            }
            ul#gallery li{
            display:block;
            }
            ul#gallery li img{
            opacity:0.5;
            height:auto;
            width:400px;
            }
            #header{
            position:static;
            margin:10px 0 0 20px;
            }
        }
    </style>
</head>
<body>
    <div id="header">
        <div id="logo"></div><!-- #logo -->
    </div><!-- #header -->

    <ul id="gallery">
        <li><a href="images/01.jpg" class="lightbox_trigger"><img src="images/01.jpg" /></a></li>
        <li><a href="images/02.jpg" class="lightbox_trigger"><img src="images/02.jpg" /></a></li>
        <li><a href="images/03.jpg" class="lightbox_trigger"><img src="images/03.jpg" /></a></li>
        <li><a href="images/04.jpg" class="lightbox_trigger"><img src="images/04.jpg" /></a></li>
        <li><a href="images/05.jpg" class="lightbox_trigger"><img src="images/05.jpg" /></a></li>
        <li><a href="images/06.jpg" class="lightbox_trigger"><img src="images/06.jpg" /></a></li>
        <li><a href="images/07.jpg" class="lightbox_trigger"><img src="images/07.jpg" /></a></li>
        <li><a href="images/08.jpg" class="lightbox_trigger"><img src="images/08.jpg" /></a></li>
        <li><a href="images/09.jpg" class="lightbox_trigger"><img src="images/09.jpg" /></a></li>
        <li><a href="images/10.jpg" class="lightbox_trigger"><img src="images/10.jpg" /></a></li>
        <li><a href="images/11.jpg" class="lightbox_trigger"><img src="images/11.jpg" /></a></li>
        <li><a href="images/12.jpg" class="lightbox_trigger"><img src="images/12.jpg" /></a></li>
        <li><a href="images/13.jpg" class="lightbox_trigger"><img src="images/13.jpg" /></a></li>
        <li><a href="images/14.jpg" class="lightbox_trigger"><img src="images/14.jpg" /></a></li>
        <li><a href="images/15.jpg" class="lightbox_trigger"><img src="images/15.jpg" /></a></li>
    </ul>

    <script>
    jQuery(document).ready(function($) {

      $('#gallery img').hover(
         function () {
           $(this).css('opacity',1)
         }, 
         function () {
           $(this).css('opacity',.4);
         }
       );

        $('.lightbox_trigger').click(function(e) {

            e.preventDefault();

            var image_href = $(this).attr("href");

            if ($('#lightbox').length > 0) { // #lightbox exists

                $('#content').html('<img src="' + image_href + '" />');

                //$('#lightbox').show();

                $('#lightbox').fadeIn('2000');
            }

            else { 

                var lightbox = 
                '<div id="lightbox">' +
                    '<p>Click to close</p>' +
                    '<div id="content">' + 
                        '<img src="' + image_href +'" />' +
                    '</div>' +  
                '</div>';

                $('body').append(lightbox);
            }

        });

        $('#lightbox').live('click', function() { 
            $('#lightbox').hide();
        });

    });
    </script>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:23:21+00:00Added an answer on June 10, 2026 at 9:23 pm

    Well, there are many ways to approach this.

    In your case, you can possible check screen size on a click event and do appropreate operations.

    Something like this:

        var winWidth = $(window).width(); //cache window width
        $(window).resize(function() {
            winWidth = $(this).width(); //updating winWidth with current window width
        });
    

    Now when the light box handler is clicked do the winWidth size checking:

      $('.lightbox_trigger').click(function(e) {
    
            e.preventDefault();
    
            var image_href = $(this).attr("href");
    
           if (winWidth > 400) {       //Checking if screen size is greater than 400
             if ($('#lightbox').length > 0) { // #lightbox exists
    
                $('#content').html('<img src="' + image_href + '" />');
    
                //$('#lightbox').show();
    
                $('#lightbox').fadeIn('2000');
              }
    
              else { 
    
                var lightbox = 
                '<div id="lightbox">' +
                    '<p>Click to close</p>' +
                    '<div id="content">' + 
                        '<img src="' + image_href +'" />' +
                    '</div>' +  
                '</div>';
    
                $('body').append(lightbox);
              }
            }
        });
    

    If you’re doin this kinda screen checking quiet often i suggest you to have a look at enquire.js http://wickynilliams.github.com/enquire.js/

    Hope it helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a demo here to illustrate my problem http://www.ttmt.org.uk/forum/gallery1/ It's a simple list
I have a demo here to illustrate my problem http://www.ttmt.org.uk/ It's just a simple
I have made the smallest demo project to illustrate my problem. You can download
Here's some code to illustrate the problem I'm running into. jsFiddle Demo <div class=normal>
Here's a minimal batch file, demo.bat , to illustrate my problem: @ECHO off set
Its too much code to paste here so, I have created demo please have
Current demo here: http://www.studioimbrue.com/sites/eliotdudik I have the tabs system working wonderfully. I'm trying to
I have ajax domain lookup script. Look here for DEMO: Here is JS code
I have a website that uses ajax jquery and facebox. Demo here : http://temp.nevergone.eu/facebox.php
UPDATE : look at the demo here: http://amit-verma.com/template_test/ i am having a slight problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.