这是一款基于Bootstrap的垂直滚动新闻特效。原生的Bootstrap只有水平的轮播图插件。该特效通过修改HTML结构和CSS样式来达到垂直滚动轮播的效果。
使用方法
在页面中引入jquery和bootstrap的相关文件。
<link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css'> <script src="http://cdn.bootcss.com/jquery/1.11.0/jquery.min.js" type="text/javascript"></script> <script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js'></script>
HTML结构
该垂直滚动新闻特效的基本HTML结构如下:
<div class="bg-demo"> <div class="container"> <div id="carousel-example-vertical" class="carousel vertical slide"> <div class="carousel-inner" role="listbox"> <div class="item active"> <p class="ticker-headline"> <a href="#"> 滚动新闻内容。。。 </a> </p> </div> ...... </div> <!-- 上下箭头按钮 --> <a class="up carousel-control" href="#carousel-example-vertical" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-up" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="down carousel-control" href="#carousel-example-vertical" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> </div>
CSS样式
为该垂直滚动新闻特效添加下面的CSS样式:
body { margin: 50px 0; } .bg-demo{ background: #66677c; } .ticker-headline { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 25px 0; margin: 0; font-size: 18px; } .carousel.vertical .carousel-inner { height: 100%; width: auto; } .carousel.vertical .carousel-inner > .item { width: auto; padding-right: 50px; -webkit-transition: 0.6s ease-in-out top; transition: 0.6s ease-in-out top; } @media all and (transform-3d), (-webkit-transform-3d) { .carousel.vertical .carousel-inner > .item { -webkit-transition: 0.6s ease-in-out; transition: 0.6s ease-in-out; } .carousel.vertical .carousel-inner > .item.next, .carousel.vertical .carousel-inner > .item.active.right { -webkit-transform: translate3d(0, 100%, 0); transform: translate3d(0, 100%, 0); top: 0; } .carousel.vertical .carousel-inner > .item.prev, .carousel.vertical .carousel-inner > .item.active.left { -webkit-transform: translate3d(0, -100%, 0); transform: translate3d(0, -100%, 0); top: 0; } .carousel.vertical .carousel-inner > .item.next.left, .carousel.vertical .carousel-inner > .item.prev.right, .carousel.vertical .carousel-inner > .item.active { -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); top: 0; } } .carousel.vertical .carousel-inner > .active, .carousel.vertical .carousel-inner > .next, .carousel.vertical .carousel-inner > .prev { display: block; } .carousel.vertical .carousel-inner > .active { top: 0; } .carousel.vertical .carousel-inner > .next, .carousel.vertical .carousel-inner > .prev { position: absolute; top: 0; width: 100%; } .carousel.vertical .carousel-inner > .next { top: 100%; } .carousel.vertical .carousel-inner > .prev { top: -100%; } .carousel.vertical .carousel-inner > .next.left, .carousel.vertical .carousel-inner > .prev.right { top: 0; } .carousel.vertical .carousel-inner > .active.left { top: -100%; } .carousel.vertical .carousel-inner > .active.right { top: 100%; } .carousel.vertical .carousel-control { left: auto; width: 50px; } .carousel.vertical .carousel-control.up { top: 0; right: 0; bottom: 50%; } .carousel.vertical .carousel-control.down { top: 50%; right: 0; bottom: 0; } .carousel.vertical .carousel-control .icon-prev, .carousel.vertical .carousel-control .icon-next, .carousel.vertical .carousel-control .glyphicon-chevron-up, .carousel.vertical .carousel-control .glyphicon-chevron-down { position: absolute; top: 50%; z-index: 5; display: inline-block; } .carousel.vertical .carousel-control .icon-prev, .carousel.vertical .carousel-control .glyphicon-chevron-up { left: 50%; margin-left: -10px; top: 50%; margin-top: -10px; } .carousel.vertical .carousel-control .icon-next, .carousel.vertical .carousel-control .glyphicon-chevron-down { left: 50%; margin-left: -10px; top: 50%; margin-top: -10px; } .carousel.vertical .carousel-control .icon-up, .carousel.vertical .carousel-control .icon-down { width: 20px; height: 20px; line-height: 1; font-family: serif; } .carousel.vertical .carousel-control .icon-prev:before { content: '\2039'; } .carousel.vertical .carousel-control .icon-next:before { content: '\203a'; }
版权声明
版权说明: 仅限用于学习和研究目的;不得将上述内容用于商业和非法用途!否则一切后果自负。我们非常重视版权问题,如有侵权请邮件至(171373236#qq.com)与我们联系处理,敬请谅解!