ボタンがクリックされたときにページをスクロールしたい。以下のコードは、sweetalert.js と sweetalert.css がなくても問題なく動作します。最初にページが一番上にスクロールしますが、アラート ボックスから [OK] ボタンをクリックすると、ページが自動的に下にスクロールします。こちらのリンクから、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>