单击按钮时,我想滚动页面。下面的代码在没有sweetalert.js和sweetalert.css的情况下工作得很好。首先,页面滚动到顶部,但当我单击“警报”框中的“确定”按钮时,页面会自动向下滚动。请从sweetalert.js链接下载这和sweetalert.css。
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"> </script>
<script src="js/sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/sweetalert.css"/>
<script>
$(document).ready(function (){
$("#click").click(function (){
$('html, body').animate({
scrollTop: $("#div1").offset().top
}, 2000);
swal({
title: "This is title",
text: "Some error occurred",
type: "error",
confirmButtonText: "Ok"
});
window.scrollTo(0, 100);
});
});
</script>
<div id="div1" style="height: 900px; width 100px">
Div1 is here.
</div>
<br/>
<div id="div2" style="height: 900px; width 100px">
Div2 is here.
</div>
<button id="click">Click here</button>
</html>发布于 2015-12-16 05:22:08
我不知道你的产出需要多少。但是,把你的滚动在确认回调,所以页面将滚动时,用户点击甜警报康弗里姆警报。以下是已编辑的代码。
$(document).ready(function (){
$("#click").click(function (){
swal({
title: "This is title",
text: "Some error occurred",
type: "error",
confirmButtonText: "Ok"
}, function(){
$('html, body').animate({
scrollTop: $("#div1").offset().top
}, 2000);
window.scrollTo(0, 100);
});
});
});或
另一种方法是在点击后将其保持在顶部。
$(document).ready(function (){
$("#click").click(function (){
$('html, body').animate({
scrollTop: $("#div1").offset().top
}, 2000);
swal({
title: "This is title",
text: "Some error occurred",
type: "error",
confirmButtonText: "Ok"
}, function(){
$('html, body').animate({
scrollTop: $("#div1").offset().top
}, 100);
});
});
});https://stackoverflow.com/questions/34303736
复制相似问题