本文实例讲述了jQuery实现的无缝广告图片左右滚动功能。分享给大家供大家参考,具体如下:
先是写了一个此功能的jQuery插件,但是一时写不出如何使用鼠标进行滚动方向的切换,于是又写了另一个可以实现切换的版本...
原理:
1.把滚动的内容复制2份放到原内容左右,这样无论向左右滚动都不会出现断掉的情况
2.改变内容样式的left值实现滚动效果,向左或向右滚动一个内容的长度后,还原并继续滚动,这样看起来就像无缝一直滚动的样子了(视觉上的效果,^_^)
3.鼠标放上去则clearInterval,移开后继续setInterval
4.移动效果写成一个方法,切换方向时调用一次即可
<style> * { margin:0; padding:0;} ul { list-style:none; margin:0; padding:0;} img { border:none;} .bar { margin:0 auto; width:800px; height:48px; overflow:hidden; line-height:48px; border:2px solid #EEE;} .bar a.a_left, .bar a.a_right{ float:left; width:11px; height:48px; background:url(a_left.png) no-repeat left center;} .bar a.a_right { float:right; background-image:url(a_right.png);} .bar_wrap { float:left; position:relative; width:776px; height:48px; white-space:nowrap; overflow:hidden;} .bar_inner { position:relative; height:48px; line-height:48px; left:0; width:2880px; white-space:nowrap;} .bar_inner ul { height:48px; overflow:hidden; float:left; width:960px;} .bar_inner ul li{ float:left;} .bar_inner ul li a{ padding:0 16px; display:block; height:48px; line-height:48px;} </style>
<body> <div class="bar"> <a href="#" class="a_left"></a> <div class="bar_wrap"> <div class="bar_inner"> <ul> <li><a href="#" title="" ><img src="/UploadFiles/2021-04-02/pic.png">var scrollBar = function(){ this.step = 14; this.speed = 100; this.inner = $(".bar_inner"); this.wrap = $(".bar_wrap"); this.ini = 0; this.pos = "l"; this.s ; } scrollBar.prototype = { check : function(){ return this.inner.width() < this.wrap.width() "left",- this.inner.width()/3 + "px"); } }, run : function(pos){ if (! this.check()){ return;} if( this.ini == 0) {this.init();} this.ini = 1; this.pos = pos; var that = this; var f = function(){ if(that.pos == "l"){ var l = parseInt( that.inner.css("left") ) - that.step; that.inner.css("left",l + "px"); //console.log(l); if ( parseInt(that.inner.css("left")) <= -( that.inner.width()/ 3 * 2) ){ that.inner.css("left",- that.inner.width() /3 + "px"); } } else { var l = parseInt( that.inner.css("left") ) + that.step; that.inner.css("left",l + "px"); //console.log( l ); if( parseInt(that.inner.css("left")) >= 0 ){ that.inner.css("left", - that.inner.width()/3 + "px"); } } } if(this.s) {clearInterval(that.s);}; this.s = setInterval( f ,that.speed); that.inner.hover( function(){ clearInterval(that.s);}, function(){clearInterval(that.s); that.s = setInterval( f ,that.speed); } ) } } var s = new scrollBar(); s.run("r"); $(".a_left").mouseover(function(){ clearInterval( s.s); s.run("l"); }) $(".a_right").mouseover(function(){ clearInterval( s.s); s.run("r"); })更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery图片操作技巧大全》、《jQuery切换特效与技巧总结》、《jQuery拖拽特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常见经典特效汇总》、《jQuery动画与特效用法总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年09月24日
2024年09月24日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】