Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Scroll One pixel from where ever the user is on screen

okay heres the scenario. I have a one page website with may sections using anchor links. Whe the user is on a secondary layout (page) and when they click on to go to a section on the main page again, for some reason the graphics dont load properly until a scroll happens. All I want to do is whenever the main layout is loaded, no matter which anchor it loads to, simply scroll the page up or down by 1 pixel.

 $.scrollTo({ top: '+=100px', left: '+=0px' }, 800);

I tried the above, but this code simply takes the user 100 pixels from the top. I don't want that to happen, i.e. not from the top but from where ever the user is on screen.

like image 765
Muhammed Bhikha Avatar asked Dec 11 '12 06:12

Muhammed Bhikha


4 Answers

use jquery scrollTop() to set the scroll position to the current scroll position + 1:

$(window).scrollTop($(window).scrollTop()+1);
like image 103
Justin McDonald Avatar answered Nov 19 '22 02:11

Justin McDonald


I have a similar problem. I want to scroll down 1 pixel and then 1 pixel up, so the user hopefully won't notice anything at all. I did this:

window.scrollBy(0, 1); // 0 pixels horizontal and 1 pixel down
window.scrollBy(0, -1); // 0 pixels horizontal and 1 pixel up

UPDATE: But I might end up using JQuery instead. All I want is the scroll event to fire and I can do that with:

$(window).scroll();
like image 25
Bjørn Stenfeldt Avatar answered Nov 19 '22 01:11

Bjørn Stenfeldt


A pure JavaScript solution without the jQuery overhead:

window.scrollY += 100;

With jQuery (and a fancy animation):

var cur = $(window).scrollTop();
$(window).animate({scrollTop: cur + 100});
like image 4
Chris Avatar answered Nov 19 '22 02:11

Chris


$("html, body").animate({scrollTop: ($(window).scrollTop() + 1)});
like image 2
Laura Chesches Avatar answered Nov 19 '22 01:11

Laura Chesches