Forum Moderators: open

Message Too Old, No Replies

scrollTo ("a specific div within a content slider")

trouble with adding scrollTo function to a working content slider

         

breaker

6:30 pm on May 26, 2011 (gmt 0)

10+ Year Member



hi everyone,

i would love some help on this problem as i am pretty new to javascript. i have a workable content slide/scroll that contains a bunch of pictures, which are themselves links to separate html pages with the same content slider. what i am trying to achieve is that when i click on an image link in the content slider and it brings me to the new page, i would like that image link that i last selected to be at the top of the content slider.

here's the html code for the anchor tag and the script for slider.

<a id="duck5" href="duck5.html" ><img src="images/duck5_tn.jpg" width="171" height="101"></a>

<script>
$(window).load(function() {
$("#mcs_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);
});
</script>

so how would i incorporate $(#mcs_container).scrollTo("#duck5"); ?

thanks for any help.

JAB Creations

5:38 am on May 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll want something like this...

var e = document.getElementById('duck5').offsetTop-10;
document.getElementById('body').scrollTop = e;


My site's content is wrapped in a divisible element with a 'body' id, you may need to use a different divisible element to use scrollTop with.

Also jQuery isn't JavaScript and I highly advise not using it for anything. It's not cross-browser compatible, it relies on totally unreliable methods such as innerHTML, it uses a lot of bandwidth and you rob yourself of being able to say you know how to program actual JavaScript.

- John

breaker

3:15 pm on May 27, 2011 (gmt 0)

10+ Year Member



Thanks, John. I appreciate the reply. I am going to implement it today. I'll let you know if/when I have success. Also, thank you for the information re: javascript vs. jquery. I wasn't aware of these differences. Could you suggest a good book or online resource for learning javascript?