▓▓▓▓▓▓ 大致介绍

  下午看到了一个送圣诞礼物的小动画,正好要快到圣诞节了,就动手模仿并改进了一些小问题

  原地址:花式轮播----圣诞礼物传送

  思路:动画中一共有五个礼物,他们平均分布在屏幕中,设置最外边的两个礼物旋转一定的角度并隐藏,动画开始,每个礼物向右移动一定的位置,然后再把第五个礼物添加到第一个礼物之前,这样这五个礼物就重新排列了,在写jQ时只管礼物位置的变化就行了,因为礼物的旋转和隐藏在样式中都已经设置好了,某个礼物如果成为第一个礼物就会自动隐藏旋转

  如果对其中的方法不熟悉的可以参考我写的jQuery学习之路,里面有讲解

▓▓▓▓▓▓ 基本结构

   代码:

     <div class="cr">
<div class="cr-l"><img src="img/fatherCh.png" alt=""/></div>
<div class="cr-icon">
<div id="cr-icon">
<img style="left:5%" src="img/gift2.png" alt=""/>
<img style="left:25%" src="img/gift2.png" alt=""/>
<img style="left:45%" src="img/gift2.png" alt=""/>
<img style="left:65%" src="img/gift2.png" alt=""/>
<img style="left:85%" src="img/gift2.png" alt=""/>
</div>
</div>
<div class="cr-r"><img src="img/family.png" alt=""/></div>
</div>

▓▓▓▓▓▓ 样式

  在css中用到了:first 和 :last 属性,这两个属性是动态的,如果文档的结构变了,这两个属性的值也会相应的改变,这样我们就不必再麻烦的判断哪个元素是最后一个元素(第一个元素),直接用这两个属性就会自动选择第一个元素和最后一个元素

         html, body {
height: 100%;
margin:;
padding:;
}
.cr{
width: 100%;
position: relative;
background: url("../img/bg.png") no-repeat 0 0;
-webkit-background-size: 100% 100%;
background-size: 100% 100%;
overflow: hidden;
}
.cr-l,.cr-r{
position: absolute;
bottom:10%;
width: 20.8%;
height: 70%;
z-index:;
}
.cr-l img,.cr-r img{
width: 100%;
position: absolute;
top:50%;
}
.cr-l{
left:;
}
.cr-r{
right:;
}
.cr-icon{
bottom: 15%;
left:;
position: absolute;
z-index:;
width: 100%;
height: 70%;
text-align: center;
}
.cr-icon img{
margin-right: 25px;
width: 10%;
vertical-align: top;
position: absolute;
bottom:;
opacity:;
transform:rotate(0deg);
transition: all 1s;
}
.cr-icon img:first-child{
transform:rotate(-90deg);
-webkit-transform:rotate(-90deg);
opacity:;
width:;
}
.cr-icon img:last-child{
transform:rotate(90deg);
-webkit-transform:rotate(90deg);
opacity:;
width:;
}

▓▓▓▓▓▓ jQuery代码

  在源码中,作者将这个五个礼物的初始位置写在了HTML结构中,我觉得不太好就在jQuery的代码中实现了,代码没有什么难的,就是对思路的实现

    $(function() {

         // 点击礼物图片,切换图片
$('#cr-icon img').click(function(){
if($(this).attr('src') == 'img/gift2.png'){
$(this).attr('src','img/gift.png');
}else{
$(this).attr('src','img/gift2.png');
}
}); var timer = null;
var oImg = $('#cr-icon img');
var end = document.body.clientWidth;
var height = document.body.scrollHeight;
// 设置高
$(".cr").css("height",height); // 设置图片的初始位置
for(var i=0;i<oImg.length;i++){
$(oImg[i]).css('left', 5+i*20+'%');
} // 图片轮换函数
function scrollLogo(){
oImg.each(function(){
var left = parseInt($(this).css('left'));
left += end * 0.2;
$(this).css('left',left);
});
$('#cr-icon img:last').insertBefore('#cr-icon img:first').css('left',end * 0.05);
} scrollLogo(); // 定时器,开始轮换
timer = setInterval(scrollLogo,1800); // 鼠标移入清楚轮换
oImg.mouseover(function(){
clearInterval(timer);
});
// 鼠标移出开始轮换
oImg.mouseleave(function() {
timer = setInterval(scrollLogo,1800);
}); });

  

  

最新文章

  1. 《Pro ASP.NET MVC 4》异常整理
  2. JavaScript写在Html页面的&lt;head&gt;&lt;/head&gt;中
  3. 洛谷10月月赛Round.1| P3399 丝绸之路 [DP]
  4. bat 自动编译运行
  5. 红字差评系列2.dwarf
  6. poj2407 Relatives 欧拉函数基本应用
  7. 8款超酷体验的jQuery/CSS3应用插件
  8. 【WCF--初入江湖】07 分布式事务
  9. 【转】declare-styleable的使用(自定义控件) 以及declare-styleable中format详解
  10. mysql sqlmap 注入尝试
  11. QLGame 2d Engine SpriteBatch类创建
  12. 快速学习使用 Windows Azure 上的 SharePoint Server 2013
  13. SE 2014年5月28日
  14. MarsEdit快速插入源代码
  15. 开启 TLS 1.3 加密协议,极速 HTTPS 体验
  16. flutter开发vscode用模拟器调试
  17. python基础-----异常问题
  18. ASP.NET MVC Action返回结果类型【转】
  19. Ubuntu18.04, WPS表格生成中文大写数字的script
  20. jQuery学习笔记(DOM操作)

热门文章

  1. Recurrent Neural Network系列1--RNN(循环神经网络)概述
  2. Linux 江湖系列阶段性总结
  3. ABP文档 - Javascript Api - AJAX
  4. Android和JavaScript相互调用的方法
  5. DataTable 转换成 Json的3种方法
  6. 防线修建 bzoj 2300
  7. PHP设计模式(七)适配器模式(Adapter For PHP)
  8. 整理下.net分布式系统架构的思路
  9. Node.js入门
  10. MySQL 优化之 MRR (Multi-Range Read:二级索引合并回表)