Pnsadeghy
Pnsadeghy

Reputation: 1289

Jquery window horizontal scroll animate with right to left direction

I am working on project that has horizontal scroll animated with jquery and it currently works very well.

My problem is when the website translates for right to left languages, the horizontal scroll needs to move right to left.

$('body').animate({scrollRight:200},150);

The above code doesn't work. How can I animate horizontal scrolling in right to left direction

Upvotes: 0

Views: 10183

Answers (1)

Boklucius
Boklucius

Reputation: 1926

Cant't you detect the page orientation and based on that scroll left or right? i.e.

function getStyle(el,styleProp){
    var x = document.getElementById(el) || document.body;
    if (x.currentStyle)
        var y = x.currentStyle[styleProp];
    else if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    return y;
}

if (getStyle(null,'direction') == 'ltr'){
    $('body').animate({scrollLeft: -200},150);
} else {
    $('body').animate({scrollLeft:200},150);
}

PS: jQuery scrollRight?

Upvotes: 2

Related Questions