views:

486

answers:

2

I'm trying to figure out how to get this to scroll vertically. I have everything in place.. it's the exact same script has the one that scrolls horizontally. I feel like there is something in the jquery code i need but I can't seem to find a good explanation of it.

here's my link I'm working on.

http://www.chohoh.com/pcs/scroll.html

+1  A: 

Well alternatively, you could select all the elements with class 'tikt-txt' and then mimic a scroll function by executing an animation which moves the elements by changing top to -10px (for scrolling down) and 10px (for scrolling up).

Assuming you have positioned class 'tikt-txt' relatively.

EDIT:

A simple example to get you started:

$('.galnext').click(function() {
   $('.tikt-txt').animate({ "top": "-=10px" }, "100");
});

$('.galprev').click(function() {
   $('.tikt-txt').animate({ "top": "+=10px" }, "100");
});

Just make sure you edit scroll2.css and replace:

.tikt-txt {background-color:transparent;height:28px;margin:0px; padding:0px; }

With

.tikt-txt {background-color:transparent;height:28px;margin:0px; padding:0px; position:relative; }
Sbm007
A: 

With this solution, I've included the jQuery mousewheel plugin... I don't like being restricted by just clicking buttons :P

Also, I didn't use the serial scroll plugin

<script type="text/javascript"> 
$(document).ready(function() {
var slideIndex = 0;
var slideBlock = $('.tikt-txt');
var slideMax = slideBlock.length - 13; // leaves 13 slides showing in the window

$('.galprev').click(function(){
 slideIndex--;
 changeSlide();
});
$('.galnext').click(function(){
 slideIndex++;
 changeSlide();
});
$('#slideshow').bind('mousewheel', function(e,d){
 var speed = Math.floor(Math.abs(d));
 if (d > 0) {
   slideIndex = slideIndex - speed; 
 } else {
   slideIndex = slideIndex + speed; 
 }
 changeSlide();
});

function changeSlide(){
 if (slideIndex > slideMax) {
  slideIndex = slideMax;
 }
 if (slideIndex < 0) {
  slideIndex = 0;
 }
 $('#slideshow').stop().scrollTo(slideBlock[slideIndex],300) 
}
});
</script>


Edit: I'll try to explain it all... I hope you can follow my ramblings LOL

Variables

  • The top most div is indexed and assigned a zero using the slideIndex.
  • The slideBlock is an array that contains all of your slides.
  • The slideMax variable takes the total number of slideBlock minus how many slides are visible on the screen at one time (13 in this case)

Events

  • These functions are called when you click on the previous or next button
  • These functions add or subtract ONE from the index (++ means add one and -- means subtract one)
  • Then they call the function to move the slides
  • The mousewheel function uses the mousewheel plugin to bind the wheel movement and calculate how far to move the slides up or down, the speed at which you roll the mouse wheel determines how much it scrolls

ScrollTo (changeSlide) function

  • This function determines if you've scrolled past the max number of slides (too far down) or below the minimum (too far up), it then sets the number appropriately to equal the maximum or minimum position
  • Now it stops any animation .stop() and calls the scrollTo function and tells it what slide number should be shown at the top of the box (slideIndex) and how long it should take to scroll that far.

So, if you have read through all of that and you're still scratching your head... change the:

slideIndex++ to slideIndex=slideIndex+7;

and the

slideIndex-- to slideIndex=slideIndex-7;

fudgey
this looks like exactly what I need it to do.. i just can't get it to work. I think there is something missing in my code to make it work.working through it .. i need a jquery for dummies book i think..
miss chohoh
thanks!! I got this to work perfectly... now I just need to study what you did. this is great, helpful. totally appreciate it!
miss chohoh
You are most welcome :)
fudgey
hey fudgey,I was going to see if you could do a simple explanation of what you did here. I have to make it scroll by 7 tickets but I also want to figure it out myself .. if it's not a pain, could you please explain this to me a bit more in depth?
miss chohoh
Explaination added above... whew (yes I can ramble with the best of them!)
fudgey
I tried this slideIndex -7 and slideIndex +7 and it isn't working for some reason.I was thinking of making another variable that does the + 7 in it like slideScrollUp = slideIndex +7 and slideScrollDown = slideIndex -7. or would that be redundant. I just couldn't get the +7 to work.
miss chohoh
I apologize, I should have been more clear...Use slideIndex = slideIndex + 7; and slideIndex = slideIndex - 7;
fudgey
i get it now... i was so close. you're amazing, thank-you. This works flawlessly!! exactly what I need it to do!
miss chohoh
my pleasure :)
fudgey