单击时,JQuery图像会滚动到顶部

时间:2016-01-14 12:56:39

标签: jquery image scroll

当我点击一张图片时,我需要滚动到页面顶部。

<p>one</p>
<img src="http://lavozdelmuro.net/wp-content/uploads/2015/07/cecil-el-leon-4.jpg" height="250" />
<p>two</p>
<img src="http://lavozdelmuro.net/wp-content/uploads/2015/07/cecil-el-leon-4.jpg" height="250" />
<p>three</p>
<img src="http://lavozdelmuro.net/wp-content/uploads/2015/07/cecil-el-leon-4.jpg" height="250" />
<p>four</p>
<img src="http://lavozdelmuro.net/wp-content/uploads/2015/07/cecil-el-leon-4.jpg" height="250" />
<p>five</p>
<img src="http://lavozdelmuro.net/wp-content/uploads/2015/07/cecil-el-leon-4.jpg" height="250" />
<p>six</p>
<img src="http://lavozdelmuro.net/wp-content/uploads/2015/07/cecil-el-leon-4.jpg" height="250" />

1 个答案:

答案 0 :(得分:0)

在头标记中添加此代码,它将有助于你: - )

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('img').click(function(){
   $('html, body').animate({scrollTop : 0},800);
   return false;
});
});
</script>