javascript - How to properly use a variable to scrollLeft within the animate function -


first, in advance help. second, mention have looked @ different questions related topic read documentation both animate() , scrollleft() on mdn think question more based on syntax rather function usage , why other questions have not been helpful me.

now, on issue. attempting modify javascript code have written 1 function can react viewport of user.

on html side, have table 1 <tr> , 3 <td>'s. 3 <td>'s filled picture , info , when user clicks on buttons below, table scrolls appropriate content. buttons work fine. problem images bigger viewport (on device) , on initial page load, image needs scrolled distance proportional both viewport , asset size (i load different assets based on viewport also). formula scroll distance, discovered, 0.5( assetwidth ) - 0.5( viewportwidth ).

so, here js have come (this inside jquery(document).ready(function($){

var scrolldistance;  if ($('#interactive-row:visible').length == 0) {     //viewport > 801px     var assetwidth = 1920;     console.log("bouta set scroldistance");     scrolldistance = ( 0.5 * assetwidth ) - ( 0.5 * $( window ).width() ); } else {     //viewport < 800px     var assetwidth = 1428;     scrolldistance = ( 0.5 * assetwidth ) - ( 0.5 * $( window ).width() ); }  //scroll 0 whne user goes "back" slider position reset (w/o variable lastclick gets messed up) $('.table-container').animate({     scrollleft: 0 }, "slow"); console.log( "scroll distance " + scrolldistance + " calculation begin." ); //move slider middle of ssi screen $('.table-container').animate({     scrollleft: += scrolldistance.valueof()  }, "slow"); 

the problem (i believe) on second-to-last line @ point intentions have browser scroll whatever number inside scrolldistance.

note: here firefox , chrome say: "syntaxerror: expected expression, got '+='[learn more]"

also, have tried using scrolldistance out adding .valueof(). put on in case there sort of type issue in javascript wasn't aware of.

feel free take @ graphic better understand trying do. graphic of browser should display

thanks in advance help, new javascript , @ all can tell me (even general pointers how write code) appreciated!

edit: occurred me may worth noting console.log() not working @ care less if scroll starts working :d


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -