[英]jQuery Slide-in respective content on button click
I have multiple content blocks that I want to slide-in from the right of the screen when the content's respective button is clicked. 单击内容的相应按钮时,我想从屏幕的右侧滑动多个内容块。 The effect I am trying to achieve is similar to http://jsfiddle.net/jtbowden/ykbgT/2/ (got it from a different post), except I want to do it on button clicks.
我想要达到的效果类似于http://jsfiddle.net/jtbowden/ykbgT/2/ (从其他帖子中获取),但我希望在单击按钮时执行此操作。
http://jsfiddle.net/ykbgT/8571/ http://jsfiddle.net/ykbgT/8571/
HTML: HTML:
<div class="links">
<a href="#" class="div1">Div 1</a>
<a href="#" class="div2">Div 2</a>
<a href="#" class="div3">Div 3</a>
<a href="#" class="div4">Div 4</a>
<a href="#" class="div5">Div 5</a>
</div>
<div id="container">
<div id="box1" class="box">Div #1</div>
<div id="box2" class="box">Div #2</div>
<div id="box3" class="box">Div #3</div>
<div id="box4" class="box">Div #4</div>
<div id="box5" class="box">Div #5</div>
</div>
jQuery: (this is for clicking on the box) jQuery :(这是用于单击框的)
$('.box').click(function() {
$(this).animate({
left: '-50%'
}, 500, function() {
$(this).css('left', '150%');
$(this).appendTo('#container');
});
$(this).next().animate({
left: '50%'
}, 500);
});
Hope this is what you want - http://jsfiddle.net/ykbgT/8574/ 希望这就是您想要的-http://jsfiddle.net/ykbgT/8574/
<div class="links">
<a href="#" id="div1">Div 1</a>
<a href="#" id="div2">Div 2</a>
<a href="#" id="div3">Div 3</a>
<a href="#" id="div4">Div 4</a>
<a href="#" id="div5">Div 5</a>
</div>
<div id="container">
<div id="box1" class="box">Div #1</div>
<div id="box2" class="box">Div #2</div>
<div id="box3" class="box">Div #3</div>
<div id="box4" class="box">Div #4</div>
<div id="box5" class="box">Div #5</div>
</div>
Jquery: jQuery的:
$('.links a').click(function() {
var linksId1 = $(this).attr('id').split('div');
var container = 'box' + linksId1[1];
var Containers=$('div#container > div[id!="'+container+'"]');
Containers.animate({
left: '-50%'
}, 500, function() {
Containers.css('left', '150%');
Containers.appendTo('#container');
});
$('#'+container).animate({
left: '50%'
}, 500);
});
As a single button: 作为一个按钮:
$('.btn').click(function() {
var $current = $('.box').first();
if($current.not(':animated')){
//////////////////////////// Original code starts
$current.animate({
left: '-50%'
}, 500, function() {
$current.css('left', '150%');
$current.appendTo('#container');
});
$current.next().animate({
left: '50%'
}, 500);
//////////////////////////// Original code ends
}
});
As per your code on div1 click it will show box 1 see this 根据您在div1上的代码,单击它将显示框1看到此
Example : http://jsfiddle.net/kevalbhatt18/1xugjfvd/ 范例 : http : //jsfiddle.net/kevalbhatt18/1xugjfvd/
I created event on link class and from link i am getting box id so one function makes all action 我在链接类上创建了事件,并从链接中获取了框 ID,因此一个函数可以执行所有操作
$('.links').click(function(e) { var temp = e.target.classList[0].replace("div", "box"); $('.box').animate({ left: '-50%' }, 1, function() { $('.box').css('left', '50%'); $('.box').appendTo('#container'); }); $('#'+temp).siblings().animate({ left: '150%' }, 500); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.