js圖片無縫滾動(dòng)插件使用詳解
本文實(shí)例為大家分享了js圖片無縫滾動(dòng)插件的具體代碼,供大家參考,具體內(nèi)容如下
css
ul {
list-style: none;
margin: 0;
padding: 0;
}
.slide-img-ul {
white-space: nowrap;
}
.slide-img-ul>li {
width: 100px;
height: 100px;
margin: 10px;
display: inline-block;
vertical-align: middle
}
.slide-img-ul>li>img {
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
}
html
<div id="slideScroll"></div> <div id="slideFast"></div>
js
;(function(window , document) {
function createImg(ele , opt) {
var def = {
arrImg: [
{src:'../img/LOGO.png' , id:'0'},
{src:'../img/zu.png' , id:'1'},
{src:'../img/zu.png' , id:'2'},
{src:'../img/zu.png' , id:'3'},
{src:'../img/zu.png' , id:'4'},
] ,
currentData: 0,
time: 50 //滑動(dòng)速度
}
//為ele添加css樣式
ele.style.width = '240px';
ele.style.height = '120px';
ele.style.overflow = 'hidden';
ele.style.border = '1px solid #eee';
ele.style.boxShadow = '0 0 8px 2px #eee';
ele.style.position = 'relative';
//Object.assign(target , source) 方法用于將所有可枚舉屬性的值從一個(gè)或多個(gè)源對(duì)象復(fù)制到目標(biāo)對(duì)象 。 返回目標(biāo)對(duì)象。
var obj = Object.assign(def , opt),
_ul = document.createElement('ul'),
str = '',
demo
_ul.setAttribute('class' , 'slide-img-ul')
obj.arrImg.map((item , index) => {
str+='<li><img src='+ item.src+' id='+item.id+'></li>'
})
demo=str+str //復(fù)制該組圖片以達(dá)到無縫連接的視覺效果
_ul.innerHTML = demo
ele.appendChild(_ul)
var myWay = setInterval(function(){calData(_ul)}, obj.time) //定時(shí)器
function calData(element){
element.style.marginLeft = -(obj.currentData)+'px'
obj.currentData++
//(為什么*120 ?)圖片總寬度(包括margin)為120px , 當(dāng)?shù)谝唤M圖片剛好溢出父級(jí)時(shí) , 父級(jí)marginLeft置0;
if(obj.currentData > obj.arrImg.length*120 ) {
obj.currentData = 0;
}
}
ele.onmouseover = function() {
clearInterval(myWay)
}
ele.onmouseout= function() {
myWay = setInterval(function(){calData(_ul)}, obj.time)
}
}
window.createImg = createImg
}(window , document))
window.onload = function() {
new createImg(document.getElementById('slideScroll'))
new createImg(document.getElementById('slideFast') ,{time:10})
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 基于javascript的無縫滾動(dòng)動(dòng)畫1
- javascript單張多張圖無縫滾動(dòng)實(shí)例代碼
- JS實(shí)現(xiàn)單張或多張圖片持續(xù)無縫滾動(dòng)的示例代碼
- 純js實(shí)現(xiàn)無縫滾動(dòng)功能代碼實(shí)例
- JavaScript基于面向?qū)ο髮?shí)現(xiàn)的無縫滾動(dòng)輪播示例
- 原生JavaScript實(shí)現(xiàn)的無縫滾動(dòng)功能詳解
- js實(shí)現(xiàn)無縫滾動(dòng)雙圖切換效果
- JS實(shí)現(xiàn)簡(jiǎn)單的文字無縫上下滾動(dòng)功能示例
- JavaScript實(shí)現(xiàn)圖片無縫滾動(dòng)效果
- js實(shí)現(xiàn)文字列表無縫滾動(dòng)效果
- js輪播圖無縫滾動(dòng)效果
- 基于javascript的無縫滾動(dòng)動(dòng)畫實(shí)現(xiàn)2
相關(guān)文章
JS字符串與二進(jìn)制的相互轉(zhuǎn)化實(shí)例代碼詳解
這篇文章主要介紹了JS字符串與二進(jìn)制的相互轉(zhuǎn)化 ,在文中給大家提到了Js之字符串和字節(jié)碼之間的相互轉(zhuǎn)換,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06
js如何準(zhǔn)確獲取當(dāng)前頁面url網(wǎng)址信息
這篇文章主要為大家介紹了js準(zhǔn)確獲取當(dāng)前頁面url網(wǎng)址信息的多種方法,包括正則法、split拆分法等,需要的朋友可以參考下2016-04-04
JavaScript實(shí)現(xiàn)圖片瀑布流和底部刷新
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)圖片瀑布流和底部刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
xmlplus組件設(shè)計(jì)系列之下拉刷新(PullRefresh)(6)
xmlplus 是一個(gè)JavaScript框架,用于快速開發(fā)前后端項(xiàng)目。這篇文章主要介紹了xmlplus組件設(shè)計(jì)系列之下拉刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
JavaScript實(shí)現(xiàn)鼠標(biāo)經(jīng)過表格行給出顏色標(biāo)識(shí)
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)鼠標(biāo)經(jīng)過表格行給出顏色標(biāo)識(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-04-04
javascript實(shí)現(xiàn)倒計(jì)時(shí)(精確到秒)
本文給大家分享的是個(gè)人項(xiàng)目中使用的javascript實(shí)現(xiàn)的精確到秒級(jí)的倒計(jì)時(shí)代碼,十分的實(shí)用,有需要的小伙伴可以參考下。2015-06-06
用javascript實(shí)現(xiàn)在小方框中瀏覽大圖的代碼
用javascript實(shí)現(xiàn)在小方框中瀏覽大圖的代碼...2007-08-08

