Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:41:46
Original
1734 people have browsed it

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>
Copy after login

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

Html code

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

Js code

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

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>
Copy after login

Js code

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

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>
Copy after login

Js code

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

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>
Copy after login

Js code

$("#slidemarginleft button").click(function(){ 
var $marginlefty = $(this).next(); 
$marginlefty.animate({ 
marginLeft:parseInt($marginlefty.css('marginLeft'),10)==0 &#63; $marginlefty.outerWidth() : 0 
}); 
});
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!