I am new to jquery and cannot understand why my code is not working. I have a horizontal layout and want to use the scrollLeft () function (which works fine with this code)
$("#next").click(function() { currentElement = currentElement.next(); scrollTo(currentElement); }); function scrollTo(element) { $(window).scrollLeft(element.position().left); }
But ideally, I would like to animate this, so when you press #next there is a nice animated effect for the left scroll function
$("#next").click(function() { currentElement = currentElement.next(); scrollTo(currentElement); }); function scrollTo(element) { $(window).animate({scrollLeft: element.position().left}, 750); }
But to no avail. What am I doing wrong?
jquery jquery-selectors
bswinnerton Jul 29 2018-11-28T00: 00Z
source share