S
S
shobique2017-10-03 20:49:49
JavaScript
shobique, 2017-10-03 20:49:49

Why does this code work fine in google chrome but fails in safari (both on mac and iphone)?

The code helps to smoothly lower the user's screen to the anchor, with the necessary indentation from the top so that the menu fixed at the top does not obscure it.

<script>
  $(document).ready(function(){
    	$('a[href^="#"]').bind('click.smoothscroll',function (e) {
    		e.preventDefault();
    		var target = this.hash,
    		$target = $(target);
    		$calculus = ( $target.offset().top - 75 );
        $target_to = $calculus.toFixed();
    		$('html, body').stop().animate({
    			'scrollTop': ($target_to+'px')
    		}, 900, 'swing');
    	});
    });
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergski, 2017-10-03
@sergski

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
  $(document).ready(function(){
        $('a[href^="#"]').on('click',function(e) {
            e.preventDefault();

            var target = this.hash,
                $target = $(target),
                $calculus = ( $target.offset().top - 75 ),
                $target_to = $calculus.toFixed();

            $('html, body').stop().animate({
                'scrollTop': ($target_to+'px')
            }, 900, 'swing');
        });
    });
</script>

works in safari for mac

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question