2020-08-22

超简单PHP/HTML复合轮播图代码

作者:G.flower
记录时间:2020-08-21

这是一个简单的由JS+CSS+PHP组成的复合轮播,由四个部分组成:
背景动态云+前景左轮播+前景右轮播+定时器显隐提示文字
运用到的有:定时器、浮动层、滚动容器的结构。其中右侧浮动轮播需要给body做onload播放标记:οnlοad="imgMove()
文章来源:https://amoi.store/

手机端演示:
在这里插入图片描述
模拟手机端:
在这里插入图片描述
电脑端演示:
在这里插入图片描述
css部分:

  1. List item
.myui-header__top{ background: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%,rgba(0,0,0,0) 100%);}
</style>
<style>
@media screen and (min-width: 1024px) { /*当屏幕最小尺寸大于1024px时,应用下面的CSS样式*/
.con-wrap {
    display:none; 
    }
.nopc{
    display:none;     
} 
.shanshuo1{
    display:none;  
}
.shanshuo2{
    display:none; 
}
.rom-margin{
    margin-top:300px;
}
/*轮播左图电脑端显示*/
#right { 
background: rgb(105,025,125,0.1); 
border-radius:5px;
overflow:hidden; 
border: 3px solid rgb(105,025,125,0.1); 
width: 68%; 
position:absolute;
z-index:5;
top:205px;
left:1%;
height:300px;
} 
#right img { 
border-radius:5px;
border: 3px solid #F2F2F2; 
height:295px;
} 
.img2{
    margin-right:3px;
}
#inright { 
float: left; 
width: 400%; 
} 
#right1 { 
float: left; 
} 
#right2 { 
float: left; 
} 
/*轮播背景云朵电脑端默认不显示*/
.gunimg{
    display:none; 
}
/*右侧轮播-显示在电脑端右侧横版图片*/
.lunbo_r{
    position:absolute;
    z-index:6;
    top:205px;
    left:70%;
    height:300px;
    width:29%;
    border-radius: 5px;
}      
.lunbo_rimg{
border-radius: 5px;
border: solid 2px rgb(105,025,125,0.1);
height:300px;
width:100%;
}
}```

 2. List item
 
```@media screen and (max-width: 1024px) { /*当屏幕最大尺寸小于1024px时,应用下面的CSS样式*/
.noshouji{  /*手机不可见的,主要是右侧轮播横版图片内容*/
    display: none;
}
a:link{ /*禁用手机端的文字链接点击效果*/
    text-decoration:none;
    }
a:visited{ /*禁用手机端的文字链接点击效果*/
    color:#fff;
    text-decoration:none; /*禁用手机端的文字点击效果*/
    }
a:hover{ /*禁用手机端的文字链接点击效果*/
    color:yellow;
    text-decoration:none;
    }
a:active{ /*禁用手机端的文字链接点击效果*/
    text-decoration:none;
}```

 3. List item
 
```.body {  /*禁用手机端的body内所有的文字效果*/
    text-decoration:none;
}
/*轮播左图手机端显示*/
#right { 
background: rgb(105,025,125,0.5); 
border-radius:5px;
overflow:hidden; 
border: 3px solid rgb(105,025,125,0.1); 
width: 60%; 
position:absolute;
z-index:5;
top:68px;
left:10px;
height:190px;
} 
#right img { 
border-radius:5px;
border: 3px solid #F2F2F2; 
height:188px;
} 
.img2{
    margin-right:3px;
}
#inright { 
float: left; 
width: 1600%; 
} 
#right1 { 
float: left; 
} 
#right2 { 
float: left; 
} ```

 4. List item
 
```/*轮播背景云朵手机端*/
.gunimg{
    width:100%;
    height:200px; 
}
/*轮播背景提示仅显示在手机端*/
.shanshuo{
    display:none;
    position:absolute;
    z-index:6;
    background-color: yellow;
    padding:2px 4px 2px 4px ;
    color:red;
    border-radius:5px;   
    width:;
}
/*轮播显示在手机端右侧*/
.lunbo_r{
    position:absolute;
    z-index:6;
    top:68px;
    left:65%;
    height:190px;
    width:32%;
    border-radius: 5px;
}      
.lunbo_rimg{
    border-radius: 5px;
    border: solid 2px rgb(105,025,125,0.1);
    height:190px;
    width:100%;
}```

 5. List item
 
```.shanshuo1{ /*显隐闪烁文字效果-左*/
    top:230px;
    left:30%;
}
.shanshuo2{/*显隐闪烁文字效果-右*/
    top:230px;
    left:73%;
}
</style>```

 6. List item

php内容:
```如果是html或者ASP,可以把<?php echo '';?>去掉即可
<body οnlοad="imgMove()">
<?php 
$i=0;  //预留的能和后台交互的响应开关,可以从网站后台给一个开关函数,0为关闭,1为开启
//新的轮播
//轮播背景层,纯纯的marquee标签实现```

 7. List item

```echo '
<div style="margin-left:-20px;background:#00ddff;" class="nopc">
<marquee class="gun" behavior="scroll" direction="right" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="50" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/11.png">  
  <img class="gunimg" src="/lunboimg/bg/33.png">   
  <img class="gunimg" src="/lunboimg/bg/22.png"> 
  <img class="gunimg" src="/lunboimg/bg/44.png"> 
  <img class="gunimg" src="/lunboimg/bg/11.png">   
</marquee>   
</div>
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="left" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="10" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/22.png">  
  <img class="gunimg" src="/lunboimg/bg/44.png">   
  <img class="gunimg" src="/lunboimg/bg/11.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png"> 
  <img class="gunimg" src="/lunboimg/bg/44.png">   
</marquee>   
</div>
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="right" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="3" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/11.png">  
  <img class="gunimg" src="/lunboimg/bg/44.png">   
  <img class="gunimg" src="/lunboimg/bg/22.png"> 
  <img class="gunimg" src="/lunboimg/bg/11.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png">   
</marquee>   
</div>
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="right" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="30" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/44.png">  
  <img class="gunimg" src="/lunboimg/bg/11.png">   
  <img class="gunimg" src="/lunboimg/bg/33.png"> 
  <img class="gunimg" src="/lunboimg/bg/22.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png">   
</marquee> 
</div>
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="left" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="17" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/22.png">  
  <img class="gunimg" src="/lunboimg/bg/33.png">   
  <img class="gunimg" src="/lunboimg/bg/11.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png"> 
  <img class="gunimg" src="/lunboimg/bg/44.png">   
</marquee>  
</div>
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="right" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="27" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/11.png">  
  <img class="gunimg" src="/lunboimg/bg/44.png">   
  <img class="gunimg" src="/lunboimg/bg/11.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png"> 
  <img class="gunimg" src="/lunboimg/bg/22.png">   
</marquee>   
</div> 
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="left" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="1" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/33.png">  
  <img class="gunimg" src="/lunboimg/bg/11.png">   
  <img class="gunimg" src="/lunboimg/bg/44.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png"> 
  <img class="gunimg" src="/lunboimg/bg/22.png">   
</marquee>   
</div> 
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="right" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="14" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/33.png">  
  <img class="gunimg" src="/lunboimg/bg/22.png">   
  <img class="gunimg" src="/lunboimg/bg/44.png"> 
  <img class="gunimg" src="/lunboimg/bg/11.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png">   
</marquee>   
</div>
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="left" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="9" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/33.png">  
  <img class="gunimg" src="/lunboimg/bg/44.png">   
  <img class="gunimg" src="/lunboimg/bg/22.png"> 
  <img class="gunimg" src="/lunboimg/bg/11.png"> 
  <img class="gunimg" src="/lunboimg/bg/44.png">   
</marquee>   
</div>    
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="right" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="5" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/44.png">  
  <img class="gunimg" src="/lunboimg/bg/22.png">   
  <img class="gunimg" src="/lunboimg/bg/33.png"> 
  <img class="gunimg" src="/lunboimg/bg/44.png"> 
  <img class="gunimg" src="/lunboimg/bg/11.png">   
</marquee>   
</div>
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="left" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="45" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/33.png">  
  <img class="gunimg" src="/lunboimg/bg/11.png">   
  <img class="gunimg" src="/lunboimg/bg/44.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png"> 
  <img class="gunimg" src="/lunboimg/bg/22.png">   
</marquee>   
</div>
<div style="margin-left:-20px;margin-top:-200px;position: absolute;z-index:2;">
<marquee class="gun" behavior="scroll" direction="right" hspace="0" vspace="0" loop="-1" left="-20" scrollamount="15" contenteditable="true"  width="100%" οnmοuseοver="this.stop();"
 οnmοuseοut="this.start();">
  <img class="gunimg" src="/lunboimg/bg/22.png">  
  <img class="gunimg" src="/lunboimg/bg/44.png">   
  <img class="gunimg" src="/lunboimg/bg/11.png"> 
  <img class="gunimg" src="/lunboimg/bg/33.png"> 
  <img class="gunimg" src="/lunboimg/bg/44.png">   
</marquee>   
</div>
';```

 1. List item
 
```//轮播前景层-左,向右滚动效果,非常简洁的轮播图,可以单独提出来用,重新设置高宽即可
echo '
<div id="right"> 
<div id="inright"> 
<div id="right1"> 
<a href="#"><img src="/lunboimg/lunbo/2.png" class="alpha" border="0" /></a> 
<a href="#"><img src="/lunboimg/lunbo/2.png" class="alpha" border="0" /></a> 
<a href="#"><img src="/lunboimg/lunbo/2.png" class="alpha" border="0" /></a> 
<a href="#"><img src="/lunboimg/lunbo/2.png" class="alpha" border="0" /></a> 
<a href="#"><img src="/lunboimg/lunbo/2.png" class="alpha" border="0" /></a> 
<a href="#"><img src="/lunboimg/lunbo/4.png" class="img2 alpha" border="0" /></a> 
</div> 
<div id="right2"></div>
</div>
</div>
<script> 
var speed=30; //数字1为最快
var tab=document.getElementById("right"); 
var tab1=document.getElementById("right1"); 
var tab2=document.getElementById("right2"); 
tab2.innerHTML=tab1.innerHTML; 
function Marquee(){ 
if(tab.scrollLeft<=0) 
tab.scrollLeft+=tab2.offsetWidth 
else{ 
tab.scrollLeft-- 
} 
} 
var MyMar=setInterval(Marquee,speed); 
tab.οnmοuseοver=function() {clearInterval(MyMar)}; 
tab.οnmοuseοut=function() {MyMar=setInterval(Marquee,speed)}; 
</script> 
';```

 2. List item
 
```//轮播前景层-右-手机端的图片-竖版
echo '
 <div class="lunbo_r nopc">
            <img class="lunbo_rimg" src="/lunboimg/lunbo/1.png" alt="" id="picture"/>
        </div>
<script type="text/javascript">
            var arr=new Array();
                arr[0]="/lunboimg/lunbo/shouji/2.png";
                arr[1]="/lunboimg/lunbo/shouji/3.png";
               ?> ```
 
 10. List item

//轮播前景层-右-电脑端的图片-横版
```echo '
 <div class="lunbo_r noshouji">
            <img class="lunbo_rimg" src="/lunboimg/lunbo/1.png" alt="" id="picture"/>
        </div>
<script type="text/javascript">
            var arr=new Array();
                arr[0]="/lunboimg/lunbo/pc/2.png";
                arr[1]="/lunboimg/lunbo/pc/3.png";```
                
 11. List item

<单独区分设备手机端执行的JS:-->

```<!--闪烁文字提示,当设备为电脑时不出现闪烁文字-->
<script language='javascript' type='text/javascript'>
function IsPC() {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone",
                    "SymbianOS", "Windows Phone",
                    "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                break;
            }
        }
        return flag;
    };
    $(document).ready(function(){
        var isPC=IsPC();
        if(isPC){
           //PC端不执行;
      }
        else{
           //移动执行;
var shortIntervalTime = 2 * 1000;
var longIntervalTime = 2 * 1000;
function cycle(id) {
    var nextId = (id == "shanshuo1") ? "shanshuo2":"shanshuo1";
    $("#" + id)//ID循环
        .delay(shortIntervalTime)
        .fadeIn(500)//淡入时长
        .delay(longIntervalTime)
        .fadeOut(500, function() {cycle(nextId)});//淡出时长
}
cycle("shanshuo1");       
        }
    });
</script>```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值