Reputation: 55
I hava a button in a form ,I want when this button clicked the scroll back to top of page .my java script function is:
function handleResponse() {
window.scrollBy(0,0).fadeIn('smooth')
}
and in my form is:
<p:commandButton icon="ui-icon-arrowthick-1-n" onclick="handleResponse" immediate="true"/>
but page is refreshed,instead of scrooling smoothy in top,what is solution?
Upvotes: 0
Views: 1812
Reputation: 1
Just add this after the <body>
tag:
<!--Back to top Button-->
<a href="#" id="btt" title="Back to Top" style="display: none;"><span></span></a>
<!--Back to top Button-->
CSS:
#btt {
position:fixed;
right:10px;
bottom:10px;
cursor:pointer;
width:50px;
height:50px;
background-color:#019934;
display:none;
-webkit-border-radius:60px;
-moz-border-radius:60px;
border-radius:60px; }
#btt span {
position:absolute;
top:8%;
left:40%;
margin-left:-8px;
margin-top: 0px;
height:0;
width:0;
border:13px solid transparent;
border-bottom-color:#ffffff; }
#btt:hover {
background-color:#254117;
opacity:1;filter:"alpha(opacity=100)";
-ms-filter:"alpha(opacity=100)"; }
and script:
$(document).ready(function(){
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('#btt').fadeIn();
} else {
$('#btt').fadeOut();
}
});
$('#btt').click(function(){
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
}); });
Upvotes: 0
Reputation: 954
Try below code. Hope it works.
$("#handleResponse").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
Upvotes: 2