![]() |
jquery and offsetting content.
Hi,
I have been browsing a load of tutorials and found one which I can understand and which is easy to implement. When I hover over an image, I want it to display a larger image next to it as a sort of 'preview' feature of the image. I have added some of my own code (the opacity bits) and edited the other jquery to suit my needs. The problem I am having is as well as displaying the corresponding image, I also want it to display a bit of text underneath the image. I am successfully appending the paragraph to the body but when I try to manipulate the Y offset, it doesn't seem to work. Here is the code: Code:
$(function(){Thanks for any help you can give me. Regards, LC. |
You probably need to add the text-offset to the mousemove event as indicated here:
Code:
$('#product_holder a img').mousemove(function(e){BTW This is probably not the best way to do this - dynamically creating the elements. Preferable would be to have the image and paragraph contained within a hidden div, and use events to change the image src, the p-text, and then show (or fade, etc.) the div. |
Ah ok, I only hardcoded the paragraph in there just to get it to position where I wanted it. I'm not sure about what I am going to do with regards to creating the individual information.
So for example, if I create just 1 hidden div and set it to display none. Code:
<div id="view"></div>Not sure how to go about writing the content for each image. Any thoughts about that? Thanks for the advice. Regards, LC. |
Code:
<div id="view">I think the src is set using css() (I should double-check this ;)): Code:
$('#viewimg').css('src','someother.gif');Code:
var imgDetails = { "key1" : ["newimagesrc.gif", "Great description here"], |
Just did a quick test, but it is attr() rather than css() to change the image source - Doh! :rolleyes:
Code:
<!DOCTYPE html>Added: Sorry that I didn't adapt your code, and I should use jQuery to add the click (or hover) event. |
Hi andrew, thanks for the reply. I examined your code and edited it slightly to make it easier for myself to work with.
Here is the code: Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" Is there a way I can tell jquery to stop what it's doing until the slideUp function finishes it's job. I tried putting .stop().slideUp bla bla and it didn't work. I know we can use stop() with animate() but clearly not with the basic css style functions. I also tried moving the iteration around to before the jquery functions(inside the click) and afterwards and no difference. Kind regards, LC. |
slideUp, like most jQuery methods, accept a callback to run when the method completes.
Code:
$('#view').slideUp('slow', function () { |
Top man, thanks very much indeed. I noticed a lot of the functions have the callback parameter but never really known what it meant or how to use it.
My images are displayed from a database so when trying to implement something like this in my site, how can I go about filling the array with the images which are retrieved rather than having to hardcode each src attribute? Edit: think i might have an idea, ill go ahead and attempt to do it. Just need to grab the src of the image which was retrieved the same as I did before and loop the values into an array? Cheers dude, Kind regards, LC. |
At some point you might want to look into pre-loading (caching) the images - if there are a number of them, or they are quite big. Essentially, you create a new-images array and setting there src's loads them in the browsers cache.
Code:
var myImgs = ['path/to/img1.jpg', 'path/to/img2.gif'];You could probably combine this with constructing the imgDetails object, so that imgDetails is built at the same time as the images are cached. |
Would this be done completely separate from the jQuery and does it need to be done before any of the jQuery is run?
Sorry I've never even looked at caching. Heard a lot but never read into it. :s Regards, LC. |
Quote:
Perhaps you could ignore the pre-loading aspect until everything else is working. |
People seem to pre-cache images by running a script in the head tag - that is, as the page is constructed - so that they are available as soon as the page is loaded.
I notice that we can also specify the size of the image(s): Code:
image1 = new Image(480, 320); |
Yea I will definitely keep this all in mind, thanks for the tips. I am going to get the functionality working between being able to select the correct image and text when I hover over that certain image. I will go back and read up on caching though once I've got this sorted.
I forgot how much I like jQuery! Was a long night and found myself debugging other peoples code so I didn't work much on the jquery from around 10pm last night. Going to do my bits and get back on it today. Will update the thread later on with any issues which arise (let me assure you there will be!) :p Regards Andrew, LC. |
How can I get all the product images src attributes and store them into an array?
I tried this: Code:
var imgDetails = new Array();Code:
$(function(){Code:
core/product_files/bench1.jpg,core/product_files/bench1.jpg,core/product_files/bench1.jpg,core/product_files/bench1.jpg,core/product_files/bench1.jpg.attr('src') to get the value but how do I initially get the images and loop the src into the array?Can I give them any naming convention as a way to target them for example: Code:
<img name="0" /> i variable to iterate through them?Any hints you can give me? EDIT: Awesome, just looked at the each() function on the jquery api and it's alerting me the src values. Regards, LC. |
Ok, I've wrote the code now to do exactly what I want:
Code:
$(function(){I'm thinking now to make it multi-dimensional and add the corresponding text to each of the indexes. What is the best way to go about doing this? Should I be doing it at the same time as I put the src's into the array? Regards, LC. |
| All times are GMT +1. The time now is 10:12 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.