Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

http://jsfiddle.net/xkuZF/6/

function func() {
    document.body.scrollTop++;
}

window.onmouseover = function() {
    clearInterval(interval);
};

window.onmouseout = function() {
    interval = setInterval(func);
};

var interval =  setInterval(func);

Do you think that there are any better ways of doing this code?

Better:

  • More options
  • Less code
share|improve this question
1  
In the future, please avoid using pastebins. As stated in the faq, it's much easier to review code when it's here, and your code is very short. –  Michael K Jul 15 '11 at 18:12
    
@Michael, you may have changed his original question which is to say about creating scroll bar manually.jsfiddle.net/xkuZF/6 –  didxga Jul 15 '11 at 18:36
    
@didxga That is the only js code I found at that fiddle - what am I missing? If there's more code, would you suggest an edit? –  Michael K Jul 15 '11 at 19:02
    
No, he is talking about how you deleted the top 25% of my post... –  Odinulf Jul 15 '11 at 19:18
    
@Michael, the <br>s thingy? –  didxga Jul 15 '11 at 19:44
add comment

1 Answer 1

To your questions:

  • More options; sure you could provide a wait time to setInterval to control the speed of the scrolling down, you could also increase the scrollTop increment to make it scroll down faster.

  • Less code; I think this is pretty much the bare minimum, a little too bare really.

I think func and interval are very generic names, I wasnt even sure if the code works / what it does until I clicked the fiddle link.

I would counter propose the following code, it is longer, but far more readable.

var scrollDownInterval;

function scrollDown() {
  document.body.scrollTop++;
}

function startScrollingDown(){
  scrollDownInterval = setInterval( scrollDown );
}

function stopScrollingDown(){
  clearInterval( scrollDownInterval );
}

window.onmouseover = function() {
  stopScrollingDown();
};

window.onmouseout = function() {
  startScrollingDown();
};

//Start scrolling down immediately
startScrollingDown(); 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.