把我的旋转木马移到另一边
Move my carousel to the other side
我已经制作了一个旋转木马,现在我需要将它移动到另一边(而不是移动到左边应该移动到右边)。是一个基于列表的非常简单的代码。查看这个网站来理解我的想法:http://diningconcepts.com/你可以看到,如果你按下箭头,旋转木马开始移动到另一边:)
我还没有添加箭头,但我的问题是,如果你能让旋转木马从左向右移动(与当前的相反)
Thanks in advance
这里是我的代码
$(function() {
var list = $('ul');
var perro = $('.perro');
function onAnimate() {
$('ul li:first-child').appendTo('ul');
$('ul li:last-child').css('margin-Left', 0);
move();
}
function move() {
$('ul li:first-child')
.animate({ marginLeft: -124 }, 1500, onAnimate);
}
list.find('li:even').addClass('even');
list.find('li:odd').addClass('odd');
list.on('mouseenter', 'li', function() {
$('ul li:first-child').stop();
});
list.on('mouseleave', move);
move();
});
div { width:1080px;overflow:hidden; }
ul { list-style-type:none;width:10000px;margin:0;padding:0; }
li { height:400px;width:108px;float:left;text-align:center;margin:0;padding:0; }
.even {background: #ccc}
.odd {background: #4e4e4e;color:#fff;}
#tomas {
width: 600px;
height: 200px;
background-color: #000;
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Documento sin título</title>
<link href="carutomstyle.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="carujava.js"></script>
</head>
<body>
<div id="new-carousel">
<ul>
<li class="perro">Item #1</li>
<li class="perro">Item #2</li>
<li class="perro">Item #3</li>
<li class="perro">Item #4</li>
<li class="perro">Item #5</li>
<li class="perro">Item #6</li>
<li class="perro">Item #7</li>
<li class="perro">Item #8</li>
<li class="perro">Item #9</li>
<li class="perro">Item #10</li>
<li class="perro">Item #11</li>
<li class="perro">Item #12</li>
</ul>
</div>
</body>
</html>
你知道新函数应该是怎样的吗?
您可以这样做:将left to right
改为right to left
,并将动画-124
改为+124
$(function() {
var list = $('ul');
var perro = $('.perro');
function onAnimate() {
$('ul li:first-child').appendTo('ul');
$('ul li:last-child').css('margin-Right', 0);
move();
}
function move() {
$('ul li:first-child')
.animate({ marginRight: 124 }, 1500, onAnimate);
}
list.find('li:even').addClass('even');
list.find('li:odd').addClass('odd');
list.on('mouseenter', 'li', function() {
$('ul li:first-child').stop();
});
list.on('mouseleave', move);
move();
});
div#new-carousel { width:1080px;overflow:hidden; }
ul { list-style-type:none;width:10000px;margin:0;padding:0; }
li { height:400px;width:108px;float:left;text-align:center;margin:0;padding:0; }
.even {background: #ccc}
.odd {background: #4e4e4e;color:#fff;}
#tomas {
width: 600px;
height: 200px;
background-color: #000;
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Documento sin título</title>
<link href="carutomstyle.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="carujava.js"></script>
</head>
<body>
<div id="new-carousel">
<ul>
<li class="perro">Item #1</li>
<li class="perro">Item #2</li>
<li class="perro">Item #3</li>
<li class="perro">Item #4</li>
<li class="perro">Item #5</li>
<li class="perro">Item #6</li>
<li class="perro">Item #7</li>
<li class="perro">Item #8</li>
<li class="perro">Item #9</li>
<li class="perro">Item #10</li>
<li class="perro">Item #11</li>
<li class="perro">Item #12</li>
</ul>
</div>
</body>
</html>
你需要改变style
ul {
margin-left:-108px;
}
修改脚本功能
$(function() {
var list = $('ul');
var perro = $('.perro');
function onAnimate() {
$('ul li:first-child').css('margin-Left', 0);
$('ul li:last-child').prependTo('ul');
move();
}
function move() {
$('ul li:first-child')
.animate({ marginLeft: 108 }, 1500, onAnimate);
}
list.find('li:even').addClass('even');
list.find('li:odd').addClass('odd');
list.on('mouseenter', 'li', function() {
$('ul li:first-child').stop();
});
list.on('mouseleave', move);
move();
});
相关文章:
- 知道为什么我的旋转木马不会自动更改图片吗
- 禁用旋转木马中的下一个按钮和上一个按钮
- 旋转木马;启用内容安全策略时无法工作
- 在引导程序旋转木马中显示下一个图像
- 猫头鹰旋转木马2罐头't使渐变动画工作
- 猫头鹰旋转木马宽度计算错误
- 猫头鹰旋转木马动画未在Chrome中应用
- 猫头鹰旋转木马:无法读取属性'visibleItems'的未定义
- 在Javascript中设置多个小图像(如旋转木马)
- 如何使引导旋转木马保持图像纵横比
- 使用旋转木马在元素上切换类
- 将图像传递到Angular UI引导旋转木马
- 当ons惰性重复检测到更改时,如何使用ons旋转木马刷新列表
- 猫头鹰旋转木马2-拖动方向
- 带有JQuery和CSS的3D旋转木马-渲染不正确
- 如何在猫头鹰旋转木马中滑动所有可见项目,而不是使用上一个/下一个按钮
- 在基于DOM元素而非索引的引导旋转木马中跳到另一张幻灯片
- 使引导旋转木马子弹滑动另一个旋转木马
- 将CSS应用于旋转木马幻灯片上的另一个span
- 把我的旋转木马移到另一边