国产精品一区二区三区……-大杳蕉伊人欧美一本遒在饯-日本不卡一区免费在线观看-国产亚洲欧美中文字幕

400-800-9385
網(wǎng)站建設(shè)資訊詳細(xì)

前端制作之修改swiper 的圓點(diǎn)為svg繪制的圓形

發(fā)表日期:2022-10-26 09:47:01   作者來源:林志平   瀏覽:1544   標(biāo)簽:前端制作    
在網(wǎng)站的制作中,不可避免的會需要制作banner的輪播,大多數(shù)效果都是大同小異,一般體現(xiàn)在banner圖上文字位置的變化,左右切換箭頭的效果,或者是圓點(diǎn)修改的效果,例如下圖所示的圓點(diǎn)做成帶有動畫效果的圓形:

效果

首先,需要明白怎么用svg繪制一個(gè)圓形,用svg繪制圓形可以通過設(shè)置circle來實(shí)現(xiàn),需要設(shè)置確定的圓心和半徑,設(shè)置圓心需要的是cx和cy,設(shè)置半徑需要的是r,而fill是填充圓的顏色,stroke 屬性是用來描邊的,如下所示:

html1

現(xiàn)在可以先開始構(gòu)建html的內(nèi)容,例如是每一屏的內(nèi)容和設(shè)置默認(rèn)的圓點(diǎn),如下所示:
 

html2


然后就是設(shè)置輪播的css樣式,如以往的一致,需要注意的是設(shè)置會轉(zhuǎn)動的圓環(huán)的樣式,如下所示:
.banner .swiper-pagination{ position: absolute; top: 50%; left: 7%; bottom: auto; transform: translateY(-50%); box-sizing: border-box; font-size: 0; width: auto; }
.banner .swiper-pagination-bullet{ position: relative; margin: 0 auto!important; cursor: pointer; background: none; width: auto; height: auto; opacity: 1; display: block; padding: 14px 0; }
.banner .swiper-pagination-bullet svg { display: block; width: 16px; height: 16px; position: relative; z-index: 5; }
.banner .swiper-pagination-bullet svg circle{ stroke-dasharray: 50; stroke-dashoffset: 50; transition: stroke-dashoffset 0.6s ease-out; -webkit-transition: stroke-dashoffset 0.6s ease-out; -moz-transition: stroke-dashoffset 0.6s ease-out; -o-transition: stroke-dashoffset 0.6s ease-out; -ms-transition: stroke-dashoffset 0.6s ease-out; }
.banner .swiper-pagination-bullet span{ position: absolute; z-index: 4; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 15px; height: 15px; border: 2px solid transparent; border-radius: 50%; box-sizing: border-box; transition: border-color 0.3s ease-out; -webkit-transition: border-color 0.3s ease-out; -moz-transition: border-color 0.3s ease-out; -o-transition: border-color 0.3s ease-out; -ms-transition: border-color 0.3s ease-out; }
.banner .swiper-pagination-bullet span:after { content: ""; width: 10px; height: 10px; border-radius: 50%; background-color: #FFFFFF; position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; }
.banner .swiper-pagination-bullet-active span:after { opacity: 0; }
 .banner .swiper-pagination-bullet-active svg circle { stroke-dashoffset: 0; transition: stroke-dashoffset 5s ease-out; -webkit-transition: stroke-dashoffset 5s ease-out; -moz-transition: stroke-dashoffset 5s ease-out; -o-transition: stroke-dashoffset 5s ease-out; -ms-transition: stroke-dashoffset 5s ease-out; }
.banner .swiper-pagination-bullet-active span { border-color: rgba(255, 255, 255); }
然后設(shè)置關(guān)于swiper js,需要注意的是生成分頁器時(shí)執(zhí)行的onPaginationRendered,如下所示:
var swiper = new Swiper('.banner', {
pagination: '.carouselImg .swiper-pagination',
paginationClickable: true,
nextButton: '.carouselImg .swiper-button-next',
         prevButton: '.carouselImg .swiper-button-prev',
speed: 1000,
autoplay: 4500,
         autoplayDisableOnInteraction: false,
onPaginationRendered:function(swiper, paginationContainer){
$('.carouselImg .swiper-pagination-bullet').append('<svg><circle cx="8" cy="8" r="6.5" stroke="#ff7500" stroke-width="2" fill="none"/></svg><span></span>');
            },
observer:true,//修改swiper自己或子元素時(shí),自動初始化swiper
            observeParents:true,//修改swiper的父元素時(shí),自動初始化swiper
});
如沒特殊注明,文章均為方維網(wǎng)絡(luò)原創(chuàng),轉(zhuǎn)載請注明來自http://pdcharm.com/news/6567.html
冕宁县| 高唐县| 虎林市| 来宾市| 大悟县| 江都市| 岑溪市| 河间市| 上杭县| 班玛县| 南开区| 永修县| 胶南市| 丰顺县| 三原县| 西昌市| 遵化市| 澜沧| 家居| 漳浦县| 铁力市| 乌兰察布市| 岳池县| 岳池县| 红安县| 土默特左旗| 土默特左旗| 密云县| 都江堰市| 中宁县| 沙洋县| 建昌县| 麻城市| 开原市| 临高县| 茌平县| 翁源县| 通道| 清苑县| 周口市| 罗田县|