Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

scroll btn

 
    // when click a btn page scroll  and go to home   
    $(window).scroll(function () {
        if ($(this).scrollTop() > 200) {
            $("#scroll-top").fadeIn(100)
        } else { $("#scroll-top").fadeOut()}
    })

    $("#scroll-top").click(function () {
        $("html,body").animate({ scrollTop: 0 }, "3000")
    })

// when click a link and go to section smoothly
// smooth scroll for all browser
	$('a').click(function (event) {
		if (this.hash !== '') {
			event.preventDefault();
			let hash = this.hash;
			$('html,body').animate({ scrollTop: $(hash).offset().top }, 800, function () {
				window.location.hash = hash;
			});
		}
	});
 
PREVIOUS NEXT
Tagged: #scroll #btn
ADD COMMENT
Topic
Name
5+5 =