用jquery写一个简单的广告动画效果

广告动画效果是用jquery的annimate实现的,实现起来很简单,代码如下:


//实现广告动画的原理是将N张图片高度设置成一样,并纵向排列在一起
//每张图片对应一个index,通过index++移动对应的高度,从而实现切换图片的效果
//动火过程是通过jQuery的animate()方法实现的
$(function(){
	$('#num li').mouseover(function(){
		//jQuery.index()方法获得该li在ul下的位置,从0开始
		var index=$('#num li').index(this);
		showImage(index);
//页面初始化时鼠标模拟停在第一个li上
}).eq(0).mouseover();
			
var taskId;
var index=0;
//hover(over,out):模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)
$('#d1').hover(function(){
	//鼠标悬停在图片上时消除定时任务
	clearInterval(taskId);
},function(){
	//设置一个定时任务每2秒执行一次,即切换到下一张图片
	taskId=setInterval(function(){
		showImage(index);
		index++;
		if(index==5){
			index=0;
		}
	},2000);
  }).mouseleave();
});

//显示图片的方法
function showImage(index){
	//stop(true):在执行当前动画之前,先清除之前未完成的动画
	//animate方法是执行动画,请参照jquery文档
	$('#adv').stop(true).animate({'top':-index*217},1000);
	//更改li按钮的样式
	$('#num li').eq(index).addClass('on').siblings().removeClass('on');
}

完整源代码的下载地址:http://download.csdn.net/detail/xulianghh/5091050

好的,以下是一个简单的相册图集页面的示例,使用了Bootstrap和jQuery并添加了动画效果: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>相册图集页面</title> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.3.1/css/bootstrap.min.css"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <h1>我的相册</h1> <div class="row gallery"> <div class="col-md-4"> <img src="https://picsum.photos/800/600?random=1"> </div> <div class="col-md-4"> <img src="https://picsum.photos/800/600?random=2"> </div> <div class="col-md-4"> <img src="https://picsum.photos/800/600?random=3"> </div> <div class="col-md-4"> <img src="https://picsum.photos/800/600?random=4"> </div> <div class="col-md-4"> <img src="https://picsum.photos/800/600?random=5"> </div> <div class="col-md-4"> <img src="https://picsum.photos/800/600?random=6"> </div> </div> </div> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <script src="script.js"></script> </body> </html> ``` 其中,`style.css`文件包含以下样式: ```css .gallery { margin-top: 50px; } .gallery img { max-width: 100%; height: auto; cursor: pointer; transition: transform 0.2s ease-out; } .gallery img:hover { transform: scale(1.1); } ``` `script.js`文件包含以下JavaScript代码: ```javascript $(function() { $('.gallery img').click(function() { var src = $(this).attr('src'); var modal = $('<div class="modal fade"><div class="modal-dialog"><div class="modal-content"><div class="modal-body"><img src="' + src + '"></div></div></div></div>'); modal.modal(); }); }); ``` 这段代码添加了一个点击事件,当图片被点击时,会弹出一个模态框显示图片。在模态框中使用了Bootstrap的样式,并使用jQuery动态生成了模态框的结构。 希望这个示例可以帮助你制作出一个相册图集页面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值