• Resolved laurine7

    (@laurine7)


    Hi!
    I’m using the crelly slider, and I really like it!

    I’ve used an image of an arrow with a link attached to it to scroll down the page. It now just jumps to the section that I want it to link to. Can I make it scroll down, rather than just jumping to it?

    I think it can be done using some css, but I can’t figure out how!

    Could you help?
    Thanx!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Fabio Rinaldi

    (@fabiorino)

    Hello, this is something that could be done with jQuery. Just copy-paste this code at the end of you header.php file

    <script type="text/javascript">	
    	// Select all links with hashes
    	(function($) {
    		$('a[href*="#"]')
    		  // Remove links that don't actually link to anything
    		  .not('[href="#"]')
    		  .not('[href="#0"]')
    		  .click(function(event) {
    			// On-page links
    			if (
    			  location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') 
    			  && 
    			  location.hostname == this.hostname
    			) {
    			  // Figure out element to scroll to
    			  var target = $(this.hash);
    			  target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
    			  // Does a scroll target exist?
    			  if (target.length) {
    				// Only prevent default if animation is actually gonna happen
    				event.preventDefault();
    				$('html, body').animate({
    				  scrollTop: target.offset().top
    				}, 1000, function() {
    				  // Callback after animation
    				  // Must change focus!
    				  var $target = $(target);
    				  $target.focus();
    				  if ($target.is(":focus")) { // Checking if the target was focused
    					return false;
    				  } else {
    					$target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
    					$target.focus(); // Set focus again
    				  };
    				});
    			  }
    			}
    		  });
    	  })(jQuery);
    </script>

    (code based on this article https://css-tricks.com/snippets/jquery/smooth-scrolling/)

    Thread Starter laurine7

    (@laurine7)

    Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Scroll down on click link’ is closed to new replies.