Javascript 反转的Div滑块
这是divslider示例的链接: 但在本例中,div从右向左移动 但是我现在想把div从左移到右。。这个网站里面已经有一个编辑器了。 所以请帮我反向移动div。因为在我的代码里,我想两边都要Javascript 反转的Div滑块,javascript,jquery,Javascript,Jquery,这是divslider示例的链接: 但在本例中,div从右向左移动 但是我现在想把div从左移到右。。这个网站里面已经有一个编辑器了。 所以请帮我反向移动div。因为在我的代码里,我想两边都要 $('.box').click(function() { $('.box').each(function() { if ($(this).offset().left < 0) { $(this).css("left", "150%");
$('.box').click(function() {
$('.box').each(function() {
if ($(this).offset().left < 0) {
$(this).css("left", "150%");
} else if ($(this).offset().left > $('#container').width()) {
$(this).animate({
left: '50%',
}, 500 );
} else {
$(this).animate({
left: '-150%',
}, 500 );
}
});
});
以下是我在你的JS小提琴上的表现:
$('.box').click(function() {
$('.box').each(function() {
if ($(this).offset().left < 0) {
$(this).animate({
left: '50%',
}, 500 );
} else if ($(this).offset().left > $('#container').width()) {
$(this).css({
'left': '-150%',
} );
} else {
$(this).animate({
left: '150%',
}, 500 );
}
});
});
这就是你的意思吗
#box1 {
background-color: green;
left: 150%; /* changed this */
}
#box3 {
background-color: red;
left: -150%; /* changed this */
}
及
非常感谢Brain,但我试过你的代码,它不起作用。我在问题中发布的链接,该网站有一个编辑器,你可以去那里查看。不过还是要感谢你的尝试,如果可能的话,请尝试让我知道正确的代码。老兄,我还需要你帮我一个小忙,你能不能也自动制作div的卷轴。。我的意思是,当我没有像幻灯片一样单击dey shud自动滚动时,但是当我单击它们时,它们会自动滑动,因为它们是红色的..$'.box'.readyfunction{var refreshId=setInterval function{$'.box'.eachfunction{if$this.offset.left<0{$this.cssleft,150%;}else if$this.offset.left>$'container'.width{$this.animate{left:'50%,},500;}else{$this.animate{left:'150%,},500;},4000;};我试图将此代码附加到您昨天发送的代码中,但此代码有时会产生问题,我不知道有什么错。您要做的很简单:setTimoutfunction{}$'.box'。单击;,5000}; '5000’表示五秒钟的延迟。如果有机会,请投票看看你评论上面的代码。。我就是这么做的。但这造成了一个小问题。有时div重叠,例如,当我按left scroll时,5秒间隔自动触发滚动,div重叠。你想让我把全部密码都发出去吗。。给我你的电子邮件ID。
$('.box').click(function() {
$('.box').each(function() {
if ($(this).offset().left > $('#container').width()) {
$(this).css("left", "-150%");
} else if ($(this).offset().left < 0) {
$(this).animate({left:'50%'},500);
} else {
$(this).animate({left:'150%'},500);
}
});
});