How to do scroll position div for an image

1

I'm using a script that when triggered positions me into a specific div , it's working, but the code I have does this from a link text and I'm trying to fit it into an image and that the same as another div . The image I need is this:

ThescriptIhaveisthis:

Whattriggers:

<ahref="#bottom" id="top">Clique para Posiconar</a>

What positions:

$('a[href^="#"]').on('click', function(event) {
var target = $( $(this).attr('href') );
if( target.length ) {
    event.preventDefault();
    $('html, body').animate({
        scrollTop: target.offset().top
    }, 1000);
}

});

The page with the code working so far can be seen here:

Example

    
asked by anonymous 24.03.2016 / 13:46

1 answer

1

To do the same with a div, you can insert an attribute as "data-href" and build on it. It would look like this:

$ ('.div_class'). on ('click', function (event) { var target = $ ($ (this) .attr ('data-href'));   event.preventDefault ();   $ ('html, body'). animate ({       scrollTop: target.offset (). top   }, 1000); });

    
24.03.2016 / 16:24