页面中间是旋转木马的效果,作为一个不是前端的淫,研究了一天才弄出来,感觉这个应该可以用在大屏或者是首页上。
附件里有这个FRM和css
css我就不写了
FRM 我直接放了一个绝对画布,给他了一个初始化事件
- setTimeout(
- function(){
- $("div[widgetname='ABSOLUTE0']").append("<div id=\"box\"><div class=\"slide\"><ul><li><a href=\"#\"><img src=\"http://img.mukewang.com/52da54ed0001ecfa04120172.jpg\" alt=\"啊啊啊\"></a></li><li><a href=\"#\"><img src=\"http://img.mukewang.com/52da54ed0001ecfa04120172.jpg\" alt=\"啊啊啊\"></a></li><li><a href=\"#\"><img src=\"http://img.mukewang.com/52da54ed0001ecfa04120172.jpg\" alt=\"啊啊啊\"></a></li><li><a href=\"#\"><img src=\"http://img.mukewang.com/52da54ed0001ecfa04120172.jpg\" alt=\"啊啊啊\"></a></li><li><a href=\"#\"><img src=\"http://img.mukewang.com/52da54ed0001ecfa04120172.jpg\" alt=\"啊啊啊\"></a></li></ul><div class=\"arraw\"><a href=\"javascript:;\" class=\"next\"></a><a href=\"javascript:;\" class='prev'></a></div></div></div><script>var box = document.querySelector('#box');var slide = document.querySelector('.slide');var arraw = document.querySelector('.arraw');var lis = document.querySelectorAll('li');var json = [ { width:400,top:20,left:120,opacity:20,z:2,id:1},{ width:600,top:70,left:50,opacity:60,z:3,id:2},{ width:800,top:100,left:150,opacity:100,z:4,id:3},{ width:600,top:70,left:350,opacity:60,z:3,id:4},{ width:400,top:20,left:370,opacity:20,z:2,id:5}];var next = document.querySelector('.next');var prev = document.querySelector('.prev');var timer = null;var flag = true;move();run();function run(){clearInterval(timer);timer = setInterval(function(){if(flag == true){flag = false;move(true);}},500);}function move(x){if(x != undefined){if(x){json.push(json.shift());}else{json.unshift(json.pop());};};for(var i = 0; i<json.length; i++){animate(lis[i],{width: json[i].width,top: json[i].top,left: json[i].left,opacity: json[i].opacity,zIndex: json[i].z},function(){flag = true;})};}function animate(obj, json, callback){clearInterval(obj.timer);obj.timer = setInterval(function(){var stoped = true;for(var k in json){var leader = 0;if(k == 'opacity'){leader = Math.round(getStyle(obj, k)*100) || 100;}else {leader = parseInt(getStyle(obj, k)) || 0;};var step = (json[k]-leader)/10;step = step > 0? Math.ceil(step) : Math.floor(step);leader = leader + step;if(k == 'opacity'){obj.style[k] = leader/100;obj.style['filter'] = 'alpha(opacity='+ leader +')';}else if(k == 'zIndex'){obj.style['zIndex'] = json[k];console.log(666);}else{obj.style[k] = leader + \"px\";}if(leader != json[k]){stoped = false;}};if(stoped){clearInterval(obj.timer);callback && callback();};},50);};function getStyle(obj, attr){if(obj.currentStyle){return obj.currentStyle[attr];}else{return window.getComputedStyle(obj, null)[attr];};};</script>")
-
- },20);
复制代码 密密麻麻的 也看不清,下面是分开的html和js
- <div id="box">
- <div class="slide">
- <ul>
- <li><a href="#"><img src="http://img.mukewang.com/52da54ed0001ecfa04120172.jpg" alt="啊啊啊"></a></li>
- <li><a href="#"><img src="http://img.mukewang.com/52da54ed0001ecfa04120172.jpg" alt="啊啊啊"></a></li>
- <li><a href="#"><img src="http://img.mukewang.com/52da54ed0001ecfa04120172.jpg" alt="啊啊啊"></a></li>
- <li><a href="#"><img src="http://img.mukewang.com/52da54ed0001ecfa04120172.jpg" alt="啊啊啊"></a></li>
- <li><a href="#"><img src="http://img.mukewang.com/52da54ed0001ecfa04120172.jpg" alt="啊啊啊"></a></li>
- </ul>
- <div class="arraw">
- <a href="javascript:;" class="next"></a>
- <a href="javascript:;" class='prev'></a>
- </div>
- </div>
- </div>
复制代码 这个是初始化后添加的div
然后下面这个是js
- <script>
- var box = document.querySelector('#box');
- var slide = document.querySelector('.slide');
- var arraw = document.querySelector('.arraw');
- var lis = document.querySelectorAll('li');
- var json = [
- {
- width:400,
- top:20,
- left:120,
- opacity:20,
- z:2,
- id:1
- },
- {
- width:600,
- top:70,
- left:50,
- opacity:60,
- z:3,
- id:2
- },
-
- {
- width:800,
- top:100,
- left:150,
- opacity:100,
- z:4,
- id:3
- },
-
- {
- width:600,
- top:70,
- left:350,
- opacity:60,
- z:3,
- id:4
- },
- {
- width:400,
- top:20,
- left:370,
- opacity:20,
- z:2,
- id:5
- }
-
- ];
- var next = document.querySelector('.next');
- var prev = document.querySelector('.prev');
- var timer = null;
- var flag = true;
- move();
- run();
- function run(){
- clearInterval(timer);
- timer = setInterval(function(){
- if(flag == true){
- flag = false;
- move(true);
- }
- },500);
- }
- function move(x){
- if(x != undefined){
- if(x){
- json.push(json.shift());
- }else{
- json.unshift(json.pop());
- };
- };
- for(var i = 0; i<json.length; i++){
- animate(lis[i],{
- width: json[i].width,
- top: json[i].top,
- left: json[i].left,
- opacity: json[i].opacity,
- zIndex: json[i].z
- },function(){flag = true;})
- };
- }
- function animate(obj, json, callback){
- clearInterval(obj.timer);
- obj.timer = setInterval(function(){
- var stoped = true;
- for(var k in json){
- var leader = 0;
- if(k == 'opacity'){
- leader = Math.round(getStyle(obj, k)*100) || 100;
- }else {
- leader = parseInt(getStyle(obj, k)) || 0;
- };
- var step = (json[k]-leader)/10;
- step = step > 0? Math.ceil(step) : Math.floor(step);
- leader = leader + step;
- if(k == 'opacity'){
- obj.style[k] = leader/100;
- obj.style['filter'] = 'alpha(opacity='+ leader +')';
- }else if(k == 'zIndex'){
- obj.style['zIndex'] = json[k];
- console.log(666);
- }else{
- obj.style[k] = leader + "px";
- }
- if(leader != json[k]){
- stoped = false;
- }
- };
- if(stoped){
- clearInterval(obj.timer);
- callback && callback();
- };
- },50);
- };
- function getStyle(obj, attr){
- if(obj.currentStyle){
- return obj.currentStyle[attr];
- }else{
- return window.getComputedStyle(obj, null)[attr];
- };
- };
- </script>
复制代码 按照我上面的代码就可以实现这个旋转木马了,我们公司的前端和美工都被我问烦了。。。。
编辑于 2018-1-8 10:05
|