国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

詳解用backgroundImage解決圖片輪播切換

2024-07-11 09:00:11
字體:
來源:轉載
供稿:網友

單dom節點實現輪播

利用backgroundImage可以添加多張圖片,以及位置偏移實現輪播效果

  • 創建一個div;并用backgroundImage給div附圖片
  • 利用backgroundPosition調節位置
  • 利用css3 transition調節過渡
  • 即可替代簡單的圖片切換
  /**        * 播放圖片        */    function playImage(src) {        if (animaitionFinshed) return;        if (!_imageEl) {            _imageEl = document.createElement('div')            _imageEl.className = `swiper_container`;            _imageEl.style.backgroundImage = `url(${src.url})`;            _imageEl.setAttribute("data-img", src.url);            elContainer.appendChild(_imageEl);        } else {            animaitionFinshed = true;            let width = elContainer.clientWidth, height = elContainer.clientHeight;            let preImage = _imageEl.getAttribute("data-img");            _imageEl.style.backgroundImage = `url(${preImage}),url(${src.url}) `;            _imageEl.style.backgroundPositionX = `center,${width + 20}px`;            setTimeout(() => {                _imageEl.style.transition = "all 0.8s ease";                _imageEl.style.backgroundPositionX = `-${width + 20}px,center`;            }, 0);            setTimeout(() => {                _imageEl.style.transition = "none";                _imageEl.style.backgroundImage = `url(${src.url}) `;                _imageEl.style.backgroundPositionX = `center`;                _imageEl.setAttribute("data-img", src.url)                animaitionFinshed = false;            }, 800)        }    }

源代碼

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安岳县| 启东市| 杂多县| 星座| 普格县| 广东省| 泊头市| 喜德县| 临泉县| 汉源县| 平武县| 克拉玛依市| 大关县| 屏山县| 江达县| 土默特右旗| 崇礼县| 洛阳市| 库车县| 桐乡市| 宕昌县| 徐汇区| 綦江县| 肇源县| 青岛市| 稻城县| 洪雅县| 南安市| 含山县| 莱西市| 南皮县| 江川县| 天等县| 平果县| 嵊泗县| 福海县| 赤城县| 连城县| 惠来县| 理塘县| 含山县|