I’m trying to create a simple event where, when the user hovers over a unique sentence in a box of sentences, the prefixed image div on the left slides left (like image goes out and another one slides in) to show the current sentences image. When not hovering over anything, the home image shows as default image. Also, the sentences aren’t structured to be on new lines, some of them go on to a new line (cannot change this).
I can’t post a picture, but I tried to explain it as detailed as possible.
How should I structure this? Should I use span tags inside of a div to identify the unique sentences so that I can set that span’s background color and image event when hover over?
Please let me know the best possible solution. Thank you.
My first inclination is that yes, you will need to wrap your particular pieces of text in
<span>‘s in order to make them hoverable (to the exclusion of the text around them). Semantically it also makes the most sense. You will then have to give the span some kind of id that you can use to tie in with the desired effect.Roughly, your markup would look like this:
Now you’ll need some css:
Then your jQuery could look something like this:
I don’t know how many of these sentences you plan to have in this page, or how many pages, so you may have to work on making the jQuery selector a little smarter.
See it live: http://jsfiddle.net/chippper/mMw5x/