在这个页面用jquery实现页面平滑滚动,控制界面显示某一区域;怎么写 5
1个回答
2015-04-01
展开全部
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery实现页面平滑滚动效果CsrCode.Cn</title>
<script type="text/javascript" src="/images/jquery1.3.2.js"></script>
<script type="text/javascript">
(function($){
$.extend($.fn,{
scrollTo:function(time,to){
time=time||800;
to=to||1;
$('a[href*=#]', this).click(function(){
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') &&
location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
if (to == 1) {
$('html,body').animate({
scrollTop: $target.offset().top
}, time);
}
else if(to==2){
$('html,body').animate({
scrollLeft: $target.offset().left
}, time);
}else{
alert('argument error');
}
return false;
}
}
});
}
});
})(jQuery);
</script>
<script type="text/javascript" language="javascript">
$(function(){
// $("#a111").scrollTo(600,2妯悜)
$("#a111").scrollTo(700)
});</script>
<style type="text/css" >
html{ _overflow:hidden}
body {margin:0; height:100%; overflow-y:auto}
#a111 { position:fixed; width:1000px; left:10%;}
* html #a111 {position:absolute;}
#a111 a{ display:block; width:50px; height:20px; background:#000; color:#fff; float:left;}
#a111 a:hover{ background:#f60;}
#b11{ height:1000px; background:#090;}
#b22{ height:1000px; background:#fc0;}
#b33{ height:1000px; background:#09d;}
</style>
</head>
<body>
<div id="b11">网页1</div>
<div id="b22">网页2</div>
<div id="b33">网页3</div>
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery实现页面平滑滚动效果CsrCode.Cn</title>
<script type="text/javascript" src="/images/jquery1.3.2.js"></script>
<script type="text/javascript">
(function($){
$.extend($.fn,{
scrollTo:function(time,to){
time=time||800;
to=to||1;
$('a[href*=#]', this).click(function(){
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') &&
location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
if (to == 1) {
$('html,body').animate({
scrollTop: $target.offset().top
}, time);
}
else if(to==2){
$('html,body').animate({
scrollLeft: $target.offset().left
}, time);
}else{
alert('argument error');
}
return false;
}
}
});
}
});
})(jQuery);
</script>
<script type="text/javascript" language="javascript">
$(function(){
// $("#a111").scrollTo(600,2妯悜)
$("#a111").scrollTo(700)
});</script>
<style type="text/css" >
html{ _overflow:hidden}
body {margin:0; height:100%; overflow-y:auto}
#a111 { position:fixed; width:1000px; left:10%;}
* html #a111 {position:absolute;}
#a111 a{ display:block; width:50px; height:20px; background:#000; color:#fff; float:left;}
#a111 a:hover{ background:#f60;}
#b11{ height:1000px; background:#090;}
#b22{ height:1000px; background:#fc0;}
#b33{ height:1000px; background:#09d;}
</style>
</head>
<body>
<div id="b11">网页1</div>
<div id="b22">网页2</div>
<div id="b33">网页3</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询