本文實例講述了jquery實現上下左右滑動的方法。分享給大家供大家參考。具體實現方法如下:
$("#sec").css("left","-200px").animate({"left":"0px"},500).show();
});
$("#btn2").unbind().click(function(){
$("#sec").hide();
$("#first").css("left","200px").animate({"left":"0px"},500).show();
});
$("#btn3").unbind().click(function(){
$("#first").hide();
$("#sec").css("top","200px").animate({"top":"0px"},500).show();
});
$("#btn4").unbind().click(function(){
$("#sec").hide();
$("#first").css("top","-200px").animate({"top":"0px"},500).show();
});
});
</script>
</head>
<body>
<div style="width:200px; height:200px;">
<div id="first" style="text-align:center; width:200px; height:200px;position:absolute;">
<p>第一頁</p>
<p>第一頁</p>
<p>第一頁</p>
<p>第一頁</p>
<p>第一頁</p>
</div>
<div id="sec" style="text-align:center; width:200px; height:200px; display:none;position:absolute;">
<p>第二頁</p>
<p>第二頁</p>
<p>第二頁</p>
<p>第二頁</p>
<p>第二頁</p>
</div>
</div>
<div style="width:200px; height:50px;">
<input type="button" value="向右滾動" id="btn"/>
<input type="button" value="向左滾動" id="btn2"/>
<input type="button" value="向上滾動" id="btn3"/>
<input type="button" value="向下滾動" id="btn4"/>
</div>
</body>
</html>
特別要注意:代碼中的position:absolute;一定要加上,否則不會出現效果。
希望本文所述對大家的jQuery程序設計有所幫助。
新聞熱點
疑難解答