Home  >  Article  >  Web Front-end  >  Sliding in different directions (sliding left, right, etc.) controlled by jQuery_jquery

Sliding in different directions (sliding left, right, etc.) controlled by jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:41:461711browse

Introduce jquery.js, copy the following code and run it.

<style type="text/css"> 
.slide { 
position: relative; 
height: 200; 
lightyellow; 
} 

.slide .inner { 
position: absolute; 
left: 0; 
bottom: 0; 
height: 100; 
lightblue; 
width: 100% 
} 
</style>

1. slidetoggle() alternates slidedown(), slideup()

Html code

<div id="slidebottom" class="slide"> 
<button> 
slide it 
</button> 
<div class="inner"> 
Slide from bottom 
</div> 
</div>

Js code

$('#slidebottom button').click(function() { 
$(this).next().slideToggle(); 
});

2. Slide the left side horizontally alternately Animate Left

Html code

<div id="slidewidth" class="slide"> 
<button> 
slide it 
</button> 
<div class="inner"> 
Slide from bottom 
</div> 
</div>

Js code

$("#slidewidth button").click(function(){ 
$(this).next().animate({width: 'toggle'}); 
}); 

3. Slide the left side horizontally alternately Animate Left Margin (not hidden)

Html code

<div id="slideleft" class="slide" style="width: 50%;float: right"> 
<button> 
slide it 
</button> 
<div class="inner"> 
Slide from bottom 
</div> 
</div>

Js code

$("#slideleft button").click(function(){ 
var $lefty = $(this).next(); 
$lefty.animate({ 
left:parseInt($lefty.css('left'),10)==0 &#63; -$lefty.outerWidth() : 0 
}); 
});

4. Slide to right

Html code

<div id="slidemarginleft" class="slide" style="width: 60%;float: left"> 
<button> 
slide it 
</button> 
<div class="inner"> 
Slide from bottom 
</div> 
</div>

Js code

$("#slidemarginleft button").click(function(){ 
var $marginlefty = $(this).next(); 
$marginlefty.animate({ 
marginLeft:parseInt($marginlefty.css('marginLeft'),10)==0 &#63; $marginlefty.outerWidth() : 0 
}); 
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn