Ok, I\'m building a horizontal scroll website for a photographer. We have some really nice wireframes done and I\'m looking to create a neat effect where it highlights the
Try using jQuery's scroll
event support.
http://api.jquery.com/scroll/
And have that check to see what image is on the screen - something similar to this:
Check if element is visible after scrolling
I fiddled a bit around with a script for this, and came up with a script where the items opacity is dertermined, from how far from the left side they are. so the closer the item is the more visible it becomes.
You can see the demo here: http://jsfiddle.net/XAa3Y/57/
Hope it helps.
You could modify (or better, improve) waypoints with horizontal scrolling support. It doesn't seem too hard as much as I could see.
How about something like this: http://jsfiddle.net/coltrane/Mj6ce/
In that example, I've used jQuery -- just because it helps a lot with cross-browser compatibility -- but you could easily re-build it without jQuery if that's what you need.
The basic idea is this:
overflow-x: auto;
), and it has a single immediate child div that holds all the other content items.The task involves detecting Image position, scroller position, and knowing your images width. With jQuery you'll need to use scrollLeft(), position(), width(), and the scroll() event
Here's how you do it.
var $div = $('div'),
divleft = $div.position().left;
$('div').scroll(function() {
$('img').each(function() {
img = $(this);
imgleft = img.position().left;
if (imgleft > divleft && imgleft + img.width() < divleft + $div.width()) {
$(this).css({
opacity: '1'
})
} else {
$(this).css({
opacity: '0.2'
})
}
});
})
you'll have to synthesize two figures.
a - you can find the position of the scroll using
oDiv.scrollLeft
b - once pictures are loaded - you can sum the sizes of the pictures (or if you set it mannually - you don't even have to wait for them to load.
oImg.style.width
Assuming you give the same spacing between the pictures - the math becomes obvious.
It's a little JavaScript, that's all :)