jquery编写一个幻灯片插件代码

代码语言:html

所属分类:幻灯片

代码描述:jquery编写一个幻灯片插件代码

代码标签: 幻灯片 插件

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>BFW NEW PAGE</title>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        var lbimg = function(id, imgs, hrefs, time) {
            if (hrefs == undefined) {
                hrefs = new Array(); for (var i = 0; i < imgs.length; i++) {
                    hrefs.push("#跳转"+parseInt(i+1));
                }}
            var hs = ""; var hs2 = "<div class='points'>"
            for (var i = 0; i < imgs.length; i++) {
                hs = hs+"<img src='"+imgs[i]+"' data-href='"+hrefs[i]+"'>"; hs2 = hs2+"<div class='point' data-page='"+i+"'></div>"
            }
            hs2 = hs2+"</div>"
            var hs3 = "<div class='leftcheck'>〈</div>"; var hs4 = "<div class='rightcheck'>〉</div>"; $(hs).appendTo("#"+id); $(hs2).appendTo("#"+id); $(hs3).appendTo("#"+id); $(hs4).appendTo("#"+id); var cv = $("#"+id).css("width"); var cv2 = $("#"+id).css("height"); $("#"+id).css({
                "overflow": "hidden", "display": "flex", "position": "relative"
            })
            $("#"+id+" .leftcheck,#"+id+" .rightcheck").css({
                "z-index": "99", "color": "white", "font-weight": "bold", "position": "absolute", "background-color": "rgb(0,0,0,0.2)", "height": cv2, "width": "20px", "display": "flex", "justify-content": "flex-start", "align-items": "center", "cursor": "pointer"
            })
            $("#"+id+" .rightcheck").css({
                "margin-left": (parseInt(cv.replace("px", ""))-20)+"px", "justify-content": "flex-end"
            })
            $("#"+id+" img").css({
                "width": "100%", "height": "100%"
            })
            $("#"+id+" .points").css({
                "color": "white", "position": "absolute", "width": cv, "bottom": "0", "height": "30px", "display": "flex", "justify-content": "center", "align-items": "center"
            })
            $("#"+id+" .point").css({
                "background-color": "black", "width": "10px", "height": "10px", "border-radius": "50%", "margin": "5px", "cursor": "pointer"
            })
            $(".point[data-page='0']").css("background-color", "white")
            $(".point[data-page='0']").addClass('active'); $(document).on('click', '#'+id+' img', function() {
                var href = $(this).attr('data-href'); window.location.href = href;
            })
            $("#"+id+" .leftcheck").css({
                "margin-left": "-20px"
            })
            $("#"+id+" .rightcheck").css({
                "margin-left": cv
            })
            var flag = lrflag = true; $("#"+id).mousemove(function() {
                if (lrflag) {
                    lrflag = false; $("#"+id+" .leftcheck").stop().animate({
                        "margin-left": "0px"
                    }, 500)
                    $("#"+id+" .rightcheck").stop().animate({
                        "margin-left": (parseInt(cv.replace("px", ""))-20)+"px"
                    }, 500)}})
            $("#"+id).mouseleave(function() {
                lrflag = true; $("#"+id+" .leftcheck").stop().animate({
                    "margin-left": "-20px"
                }, 500)
                $("#"+id+" .rightcheck").stop().animate({
                    "margin-left": cv
                }, 500)})
            return {
                id: id, time: time == undefined?2000: time, dir: 'left', timer: null, length: imgs.length, count: 1, imgchange: function() {
                    var that = this; var cv = $("#"+id).css("width"); clearInterval(that.timer)
                    that.timer = setInterval(function() {
                        that.imgFlag = false; $("#"+that.id+" .point").css("background-color", "black")
                        $("#"+that.id+" .point[data-page='"+that.count+"']").css("background-color", "white")
                        $("#"+that.id+" .point").removeClass('active')
                        $("#"+that.id+" .point[data-page='"+that.count+"']").addClass("active")
                        var img = $(".........完整代码请登录后点击上方下载按钮下载查看

网友评论0