Jump to content

Big flaw in my image expand/original size toggle script help...


Minimeallolla

Recommended Posts

I have come across a script that sets all images by default to 75x75pixels and clicking toggles between original size and back to 75x75px only problem is each image is in the "a.image-expand img" class. therefor when one image is expanded they all expand.. -.- any way to only expand selected image?

 

$(document).ready(function(){
	// default width and height to 75px
	$("a.image-expand img").css({'height':'75px', 'width':'75px'});

	// Click function (toggle)
	$("a.image-expand").click(function(){
		if(($("a.image-expand img").css("height") == "75px") && ($("a.image-expand img").css("height") == "75px"))
		{
			$("a.image-expand img").css({'height':'auto', 'width':'auto'});
		}
		else
		{
			$("a.image-expand img").css({'height':'75px', 'width':'75px'});
		}
	});
});

Here is the working script if anybody ever wants it.  (all codes shown are vital for a working code)

 


<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

<a class="image-expand" style="cursor: pointer" onclick="toggleSize(this)">
	<img src="Pics/roflcopter.gif" />

$(document).ready(function(){
	// default width and height to 75px
	$("a.image-expand img").css({'height':'75px', 'width':'75px'});
});

function toggleSize(_var_)
{
	image = $(_var_).children("img");

	if(($(image).css("height") == "75px") && ($(image).css("height") == "75px"))
	{
		$(image).css({'height':'auto', 'width':'auto'});
	}
	else
	{
		$(image).css({'height':'75px', 'width':'75px'});
	}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.