Results 1 to 6 of 6

Thread: jQuery Image Magnify v1.11

  1. #1
    Join Date
    Apr 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default jQuery Image Magnify v1.11

    1) Script Title: jQuery Image Magnify v1.11

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...agemagnify.htm

    3) Describe problem:

    is there a way to have the image de-magnified when a user click other image and or click outside the image.

    I don't want to image to stay up if the user click some where other then the image to de-magnified it.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Try putting this script in the head of the page after the external script tags for jQuery and the magnifier:

    Code:
    <script type="text/javascript">
    jQuery(function($){
    	$(document).click(function(e){
    		if(e.target.className === 'magnify'){return;}
    		$('.magnify').each(function(){
    			if(this.style.zIndex){$(this).click();}
    		});
    	});
    });
    </script>
    Worked here in Firefox and IE on the demo page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thats didn't work for me i have it in some php code and when i added

    Code:
    echo "<script type='text/javascript' src='js/jquery.min.js'></script>";
    
    echo "<script type='text/javascript' src='js/jquery.magnifier.js'></script>";
    
    echo "<script type='text/javascript'>";
    echo "jQuery(function($){";
    echo "	$(document).click(function(e){";
    echo "		if(e.target.className === 'magnify'){return;}";
    echo "		$('.magnify').each(function(){";
    echo "			if(this.style.zIndex){$(this).click();}";
    echo "		});";
    echo "	});";
    echo "});";
    echo "</script>";
    this to it. It made the page in IE display blank

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's no guarantee of what the served code of the page will be. View the page in the browser. Use the browser's 'view source'. Make sure the code looks like it's supposed to.

    If you want more help:

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Apr 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i got it to work by putting

    Code:
    echo "<script type='text/javascript' src='js/test.js'></script>";

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Just as a follow up, in PHP when you echo strings quoted in double quotes, that allows for the resolution of variables, globals, etc. - all kinds of things, according to the rules/logic of PHP. Sometimes unexpected results occur. I just tried your code on my wamp server and got:

    Parse error: parse error, expecting `T_VARIABLE' or `'$'' in test_script.php on line 7
    Depending upon how one counts lines, that's one of these:

    Code:
    echo "		$('.magnify').each(function(){";
    echo "			if(this.style.zIndex){$(this).click();}";
    echo "		});";
    probably the middle one. The unquoted parenthetical preceded by a $ could be expected to resolve, I guess - PHP isn't my strong suit. But I'm sure its something at least vaguely like that.

    Only by using single quotes are you assured of a literal echo. Also in javascript line breaks can be important. I don't think they are here. But it never hurts to play it safe. So you could have done:

    PHP Code:
    echo '<script type="text/javascript">' "\n";
    echo 
    'jQuery(function($){' "\n";
    echo 
    '    $(document).click(function(e){' "\n";
    echo 
    '        if(e.target.className === "magnify"){return;}' "\n";
    echo 
    '        $(".magnify").each(function(){' "\n";
    echo 
    '            if(this.style.zIndex){$(this).click();}' "\n";
    echo 
    '        });' "\n";
    echo 
    '    });' "\n";
    echo 
    '});' "\n";
    echo 
    '</script>' "\n"
    or:

    PHP Code:
    echo '<script type="text/javascript">
    jQuery(function($){
        $(document).click(function(e){
            if(e.target.className === \'magnify\'){return;}
            $(\'.magnify\').each(function(){
                if(this.style.zIndex){$(this).click();}
            });
        });
    });
    </script>'

    or even:

    Code:
    ?>
    <script type="text/javascript">
    jQuery(function($){
    	$(document).click(function(e){
    		if(e.target.className === 'magnify'){return;}
    		$('.magnify').each(function(){
    			if(this.style.zIndex){$(this).click();}
    		});
    	});
    });
    </script>
    <?php
    What you did however is fine. And there are probably other options for dealing with this sort of situation.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •