English 中文(简体)
使用 jquery 水平滑动 divs
原标题:sliding divs horizontally using jquery
  • 时间:2012-05-26 05:59:16
  •  标签:
  • jquery

我正在为我的页面设计一个滑动器, 我想知道是否有人知道如何创建从左到右的滑动 divs, 而反之亦然, 只有当相应的按钮( 左( amp; 右) 被按下时才能创建滑动 divs 。 您能帮助吗?

这是我正在尝试的代码。 我可以让幻灯片工作, 但到达终点时, 它仍然继续向右滑动或连续向左滑动。 我希望它一旦到达终点时, 动态停止, 点击更远时, 就会发出警告 。

任何人都能用一些示例编码来指导我

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Sample Slide</title>
<style type="text/css">
.total
{
height:350px;
width:75%;
border:1px solid black;
margin-left:auto;
margin-right:auto;
margin-top:15%;
}
.slidepanel
{
border:1px solid purple;
width:100%;
height:100%;
overflow-x: scroll;
overflow-y: hidden;
}
.box-wrapper 
{
width: 400%;
height: 90%;
overflow: hidden;
}

.block
{
 /* position:absolute;
  background-color:#abc;
  left:50px;
  width:90px;
  height:90px;
  margin:5px;*/
border:1px solid red;
width:24.9%;
height:98%;
float:left;
margin-left:auto;
margin-right:auto;
position:relative;
left:0px;
}
.block:nth-child(odd) {
    background: cyan;
}
.block:nth-child(even) {
    background: red;
}
</style>
 <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
 <script type="text/javascript" src="jquery.js"> </script>
<script type="text/javascript">
 $(document).ready(function() {
$("#sright").click(function(){
  $("#block1,#block2,#block3 ,#block4").animate({"left": "+=24.9%"}, "slow");
   });
});

 $(document).ready(function() {
$("#sleft").click(function(){
  $("#block1,#block2,#block3 ,#block4").animate({"left": "-=24.9%"}, "slow");
});
});

</script>
</head>
<body>
<div class="total">
<div class="slidepanel">
<center><button id="sleft">&laquo;</button> <button id="sright">&raquo;</button></center>
<div class="box-wrapper">
<div class="block" id ="block1"></div>
<div class="block" id ="block2"></div>
<div class="block" id ="block3"></div>
<div class="block" id ="block4"></div>
</div>
</div>
</div>
</body>
</html>
最佳回答

[强势工 [强势工 [1]: http://jsfiddle.net/XJVYj/ (使用上述代码)

希望这能有所帮助, 这与我先前对同一行上的东西的答复不同:

问题回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签