Hey folks. I’ve watched enough Jquery tutorials to be dangerous (and completely screw up otherwise fine sites)…but am pretty stumped at how best to accomplish an effect I am looking for.
Basically, I would like to have an image positioned to the left in a div. When the image is clicked, I would like it to scroll out of view (to the left) and then scroll BACK…to the right…but as a different (slightly changed) image. I attached a pic to get a visual because I am horrible at explaining things.
One way is to use the .animate() method to move the object off-screen, so you can then change the object, and animate it back onscreen again.
It can be more difficult though to develop your own image-change routine, which is why people commonly choose to instead find a plugin that they can make use of instead in order to achieve a similar result.
What if I took the image and made it the background of a wrapper. When the wrapper is clicked, it should be pretty easy to scroll it off screen, modify the CSS (change the background) and scroll it back?
What benefit does the wrapper serve, when moving the image itself is easily achieved by adjusting CSS properties, and the image is easily changed by setting a different src attribute?
Wouldn’t it be more efficient to use a wrapper with the image as a background? Then I could use sprites (adjusting the css class and shifting the background), and everything would be nice and smooth rather than hitting the server for a new image when it is clicked (at least initially).
That depends on what you intend to use the images for. If it’s for an image gallery, the sprites for such a gallery would be much larger than is feasible to use.
You could probably improve the code a little by storing the jquery collection in a variable and toggling one css class rather than having an ‘on’ and ‘off’ class (ie, the absence of ‘on’ is your off state):