栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

使用Javascript简单实现图片无缝滚动

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Javascript简单实现图片无缝滚动

js无缝滚动效果几乎在任何网页上都能看到它的身影,有的可能是使用插件,其实使用原始的javascript比较简单。

主要的是使用js位置知识。

1.innerHTML:设置或获取元素的html标签

2.scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距

3.offsetWidth:设置或获取指定标签的宽度

4.setInterval():设置方法定时启动

5.clearInterval();清除定时器

效果图:

先睹为快:demo

复制代码 代码如下:



   
    javascript scroll制作



   
    *{
    margin: 0;
    padding: 0;
  }
  img{max-width: 100%;}
  .container{
    max-width: 620px;
    margin: 0 auto;
    padding-top: 50px;
  }
  .text-center{text-align: center;}
  .list-inline li{
    display: inline-block;
  }
  .hide{display: none;}
  hr{
    margin:20px 0;
  }
  .tag{
    background-color: #ccc;
    padding: 5px 0;
  }
  .tag li{
    padding: 0 10px;
    border-left: 1px solid #fff;
    cursor:pointer;
  }
  .tag li:first-child{
    border-left: transparent;
  }
  .tag li.active{
    background-color: #ddd;
  }
  .scroll{
    position: relative;
    padding: 10px;
    margin-bottom: 20px;
    background-color: #ddd;
  }
  .wrap{
    overflow: hidden;
  }
  .content{
    min-width: 3000px;
    height: 200px;
  }
  .content ul{
    float: left;
  }
  .content ul li{
    display: inline-block;
    max-width: 200px;
  }
  #prev,#next{
    width: 50px;
    height: 50px;
    margin-top: -25px; 
    background-color: #ccc;
    line-height: 50px;
    text-align: center;
    cursor: pointer; 
  }
  #prev{
    position: absolute;
    left: 0;
    top:50%;
    border-radius: 0 25px 25px 0;
  }
  #next{
    position: absolute;
    right: 0;
    top:50%;
    border-radius: 25px 0 0 25px;
  }

   
       

图片滚动制作
       

   
     
       
         

               

  •            

  •            

  •            
  •      
             

         

             

       
     
     
        prev
     
     
        next
          
   
   
 

很简洁实用的代码,小伙伴们根据自己的项目需求,适当美化下即可。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/105315.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号