jquery可以是html element具有动感。
slideDown()方法通过向下滑动的方式显示选定的html element;slideDown(600)表示下一张图片在600ms内向下滑动。代码如下:
$('body').click(function() {
$('.slide').slideDown(600).addClass('active-slide');
});
slideUp()方法通过向上滑动的方式隐藏选定的html element。代码如下:
$('body').click(function() {
$('.slide').slideUp(600).addClass('active-slide');
});
fadeIn()方法通过渐进的方式显示选定的html element。代码如下:$('body').click(function() {
$('.slide').fadeIn(600).addClass('active-slide');
});
fadeOut()方法通过渐出的方式隐藏选定的html element。$('body').click(function() {
$('.slide').fadeOut(600).addClass('active-slide');
});
.animate()方法可以自定义动画。通过指定的CSS property在一定的时间内改变可以使html element动起来。animate()方法有两个参数:一是一组CSS properties,二是时间参数。
$('.icon-menu').click(function() {
$('.menu').animate({
width: "193px"
},
300);
});
比如,实现下面页面的翻转,当单击左边或者右边的arrorw时,可以实现内容和小圆点的翻页。
代码如下:
var main = function() {
$('.dropdown-toggle').click(function() {
$('.dropdown-menu').toggle();
});
// Click the next arrow
$('.arrow-next').click(function() {
// move to the next slide.
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();
// move to the next dot.
var currentDot = $('.active-dot');
var nextDot = currentDot.next();
if (nextSlide.length === 0) {
nextSlide = $('.slide').first(); // go back to the first slide.
nextDot = $('.dot').first();
}
currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');
currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');
});
// Click the previous arrow
$('.arrow-prev').click(function() {
var currentSlide = $('.active-slide');
var prevSlide = currentSlide.prev();
var currentDot = $('.active-dot');
var prevDot = currentDot.prev();
if (prevSlide.length === 0) {
prevSlide = $('.slide').last();
prevDot = $('.dot').last();
}
currentSlide.fadeOut(600).removeClass('active-slide');
prevSlide.fadeIn(600).addClass('active-slide');
currentDot.removeClass('active-dot');
prevDot.addClass('active-dot');
});
};
$(document).ready(main);