I never get any better - I’m sorry. I’ve hunted around and can’t find this covered on here. It used to be bad practice to resize an image with code but SVG files render beautifully at any scale and I’d like to try this out.
I’d like to have a series of images, each one doubling in scale when clicked then returning to its original size when clicked a second time.
Could I use transform: scale(2) somewhere in there to make it extra streamlined?
<script type="text/javascript">
function toggle(it) {
if (it.width == 200)
{it.width = 600;}
else
{it.width = 200;}
}
</script>
then
Code:
<img src="example.svg" onclick="toggle(this)"/>
but is there a tidy way to switch that 200 for original-size, and that 600 for double-size - I can't just smash in scale(2)... sorry for being so clumsy with this...
Thanks for that Nemesis - but pasting it over the original script means nothing's happening when I click the image - I know I'm missing something... but what?
try just using toggle() instead of toggle(this) and then at the toggle function add an alert to see if it triggers. You can use Chrome's web developer tools to debug your code to see whether or not the code is triggered. Just navigate to your script under the script tab, put a break point on the first line of your function and click your image. If it works, it'll break and you can step through the code.
Ah, thanks for your patience - I'm sorry, I'm way below this level of knowledge - I've no experience of debugging with Chrome, having a look for the first time now but it's 4 in the morning here and I'm a bit fuzzy. I'll look on tomorrow, unless there's an obvious problem or an alternative solution you could highlight for me? Thanks again... I'm sorry for being so needy...
Well I'll need an exact error from the debugger to help here, try to remove this as a parameter to toggle cause you maybe overwriting the object. When a function is triggered by event like on click, you have access to the this variable anywhere in the called function.the other thing you could try is adding return true to the end of the function.
doesn't seem to change anything... I'm in so far over my head. Chrome just has undefined (repeated 0 times) under that function toggle (this) line - Dreamweaver (sorry) suggests it contains a syntax error.
Easy enough to fix lol, add this.class !== undefined to the beginning of the if statement as the first condition, if that one fails it shouldn't go on to the next one. It should look like
if (this.class !== undefined && this.class.match(/enlarged/) === null) {
Bookmarks