Javascript 从右向左水平滚动
Javascript 从右向左水平滚动,javascript,jquery,css,Javascript,Jquery,Css,我发现这个提琴div从左向右滑动。我需要的是反转。从右向左滑动。您需要反转提供动画的功能。而不是 left: -($target.width()) 我提出以下建议: left: -($(this).width() - ($target.width())) 以下是我的可运行解决方案: jQuery(函数($){ $('a.panel')。单击(函数(){ var$target=$($(this.attr('href')), $other=$target.sides('.active'); i
我发现这个提琴div从左向右滑动。我需要的是反转。从右向左滑动。您需要反转提供动画的功能。而不是
left: -($target.width())
我提出以下建议:
left: -($(this).width() - ($target.width()))
以下是我的可运行解决方案:
jQuery(函数($){
$('a.panel')。单击(函数(){
var$target=$($(this.attr('href')),
$other=$target.sides('.active');
if(!$target.hasClass('active')){
$other.每个(函数(索引,自){
var$this=$(this);
$this.removeClass('active').animate({
左:0
}, 500);
});
$target.addClass('active').show().css({
左:-($(this.width()-($target.width()))
}).制作动画({
左:0
}, 500);
}
});
});代码>
#左#右{
位置:相对位置;
浮动:左;
边距:0 5px 0 0;
边框:1px纯黑;
宽度:200px;
高度:300px;
溢出:隐藏;
}
分区小组{
位置:绝对位置;
身高:100%;
宽度:100%;
显示:无;
}
目标1
目标2
目标3
如果我了解您的需求,我想它会成功的:
以下是更新的JSFIDLE:
更新了javascript:
jQuery(函数($){
jQuery(函数($){
$('a.panel')。单击(函数(){
var$target=$($(this.attr('href')),
$other=$target.sides('.active');
if(!$target.hasClass('active')){
$other.每个(函数(索引,自){
var$this=$(this);
$this.removeClass('active').animate({
左:-($target.width())
}, 500);
});
}
$target.addClass('active')
.css({
左:-($target.width())})
.show()
.制作动画({
左:0},500);
});
});
#左#右{
位置:相对位置;
浮动:左;
边距:0 5px 0 0;
边框:1px纯黑;
宽度:200px;
高度:300px;
溢出:隐藏;
}
分区小组{
位置:绝对位置;
身高:100%;
宽度:100%;
显示:无;
}
目标1
目标2
目标3
您是否尝试了边缘左侧和边缘右侧?
left: -($(this).width() - ($target.width()))
$('a.panel').click(function() {
var $target = $($(this).attr('href')),
$other = $target.siblings('.active');
if (!$target.hasClass('active')) {
$other.each(function(index, self) {
var $this = $(this);
$this.removeClass('active').animate({
left: -($target.width())
}, 500);
});
}
$target.addClass('active')
.css({
left: -($target.width())})
.show()
.animate({
left: 0}, 500);
});
});