I am trying to add a scroll event and drag event to a container. I added the scroll event to the window but cannot specify the container. I am looking to create an image sequence and cycle thru the images on scroll and on drag.
- <div id="container">
- <img src="frames/noindex_basset_02_img000.jpg" class="animated">
- <img src="frames/noindex_basset_02_img001.jpg" class="animated">
- <img src="frames/noindex_basset_02_img002.jpg" class="animated">
I have 61 images in the container, just posted to code to the first 3
- $(document).ready(function () {
- var pictureCount = $('#container img').length;
- var scrollResolution = 50;
- animateImage();
- function animateImage() {
- var currentScrollPosition = window.pageYOffset;
- var imageIndex = Math.round(currentScrollPosition / scrollResolution);
- if (imageIndex >= pictureCount) {
- imageIndex = pictureCount - 1; // Select last image
- }
- $("#container img").hide();
- $("#container img").eq(imageIndex).show();
- }
- $("#container").click(function(){
- animateImage();
- });
- $(window).on('scroll', function() {
- animateImage();
- });
- });