js help please!
- Started
- Last post
- 10 Responses
- ridg0026
Completely new to js and trying to implement this http://candrews.net/sandbox/spry… into a site I am working on. My problem is that I need to target more than one image ID on the page like so:
var map = new SpryMap({id : “image_one”, "image_two", etc
It will work with one image ID, but if i try to add another like above, it stops working for both. Can anybody help to educate a guy?
- ridg00260
*bump because Im not that smart
- ernexbcn0
Just create new vars:
var map = new SpryMap({id: "image_one"...
var anoher_map = new SpryMap({id: "image_two"...
- ridg00260
that doesn't seem to work either, at least not for both. Script only activates for the second map. Anything else I can try?
- spot130
How about this, forget about Spry and use Jquery:
- ridg00260
Sorry to keep bumping this but i am completely stuck !
I've uploaded it for anyone who wants to take a look and see what Im doing wrong:http://www.iamdanridge.com/portf…
If you look at the source code, the script is right above the title, basically I just want to apply that script to to the pieces below to the same effect. I think the problem is with the onload function replacing the first scripted function with the second and so on. Thanks for any help!
- ridg00260
Not sure that I follow lukus ... I got it to work just fine on one image, its when I try and apply it to more than one image at the same time thats the issue. I have the same cssClass applied to both elements but it only works for the second instance of the function, i.e. if i call it for two images, the script only applies to the second image, negating the first. Unless im totally missing something....?
- hey sorry - no you're not .. I misunderstood what you required.lukus_W2
- lukus_W20
I can't get two to run on a page either - I think it's down to the actual code that the toolkit uses.
I think(?) the problem might be related to something called closures .. but I'm not really knowledgeable enough about JS yet, to know for sure.
- Thanks for giving it a shot! I got an email in to the code author so my fingers crossed that he can help out. Im sure its something easy but im too unfamiliar with js to know what to look for.ridg0026
- that im just missing but im too unfamiliar with js to know what to look for.ridg0026
- you should be able to do what ernexbcn mentions above, would be interested to know what the solution is when you find out - good luck :)lukus_W2
- find out - good luck :)lukus_W2
- fugged0
i fixed it for ya: https://gist.github.com/824532
copy and paste the source into your existing js file, then you should be able to instantiate as many maps as you want.
- fugged0
lukus_W2, you were close.
There were some functions that were supposed to be closures, but they were being defined in the global scope, so no closure was created. This meant the arguments passed to it were not in the correct scope.