div产生的滚动条怎么回到顶部
我话少,直接上代码,html代码比较乱,主要为了产生垂直滚动条,看js就Ok了,jquery.js自行下载,就不提供了,so easy!其实说白了就是控制这个div的垂直滚动条的偏移,这里回到顶部,所以就设置成0。顺带着也把页面的垂直滚动条也移到了最顶端。
jquery访问servlet并返回数据到页面的方法
假设:
1、你的页面在Web-Root下,内容为:
,所用编码为utf-82、你的servlet为: HelloWorldServlet.java 映射路径为 servlet/helloWorldServlet 步骤: 1、引入jquery-1.6.4.min.js 2、编写id为userName的输入框的点击触发函数: $("#userName").keyup(function(){ $.ajax({ type: "post", url: "servlet/helloWorldServlet?userName="+$(this).val(), dataType: "json", success: function(data){ $("#showMsg").html(data.msg);//修改id为showMsg标签的html }, error: function(){ alert("请求出错"); } }) })
3、后台处理接收到的内容: request.setCharactorEncoding("utf-8"); String userName = request.getParameter("userName"); response.setCharactorEncoding("utf-8"); PringWriter out = response.getWriter(); out.print("{"msg":"你好~~"+userName+"!"}"); 注意事项: 1、这里的编码统一为utf-8 2、请求路径servlet/helloWorldServlet为相对路径,因此你的页面必须在项目的Web-Root下(也就是默认的web文件夹下,名字可能因项目配置不同而改变) 3、没了,记得给分哦,打字很辛苦的~
淘宝首页返回顶部效果怎么做到的
重写window.onscroll()事件,先将返回顶部div设置为position:fixed;right:10px;bottom:10px;display:none,一旦event.scrollTop>100(100可以设置为你想要的值)就display:block(fadeIn()),否则display:none(fadeOut())。还要设置返回顶部div点击事件,onclick(function(){$('body,html').animate({scrollTop:0},1000);}),这个什么意思不用我多说吧,既然搞Jquery,动画还是应该晓得。
<style type="css/text"> #gotop{position:fixed;right:10px;bottom:10px;display:none}</style><div id="gotop"></div><script type="javascript/text"> $(function(){ $(window).scroll(function(){ if($(window).scrollTop > 100){ $("#gotop").fadeIn(1000);//一秒渐入动画 }else{ $("#gotop").fadeOut(1000);//一秒渐隐动画 } }); $("#gotop").click(function(){ $('body,html').animate({scrollTop:0},1000); }); });</script>
