新手指導外掛程式.配合jquery使用

來源:互聯網
上載者:User

標籤:對象   radius   選取器   break   擷取   call   src   esc   case   

/*!* by zhangxinxu(.com) 2017-05-18* 新版上線時候的黑色半透明鏤空遮罩指引效果實現jQuery小外掛程式* 相容到IE8+* MIT使用協議,使用時候保留著作權* 參考:http://www.zhangxinxu.com/wordpress/?p=6171*/$.guide = function (options) {    var defaults = {        beforeFunc:function(a){a();},//執行嚮導前要處理的函數        clickFunc:function(){},        selector: ‘‘,  // 頁面提示元素選取器物,會使用匹配的第一個元素        content: ‘‘,  // 提示內容可是是字串,也可以是jQuery封裝器對象        align: ‘center‘, // center, right,        offset: {            x: 0,            y: 0        }    };    // options格式    /* [{        selector: ‘‘,          content: ‘‘,        align: ‘left‘,        offset: {            x: 0,            y: 0        }    }]    */    var urlRoot = location.href.split(‘#‘)[0].replace(/\W/g, ‘‘) + ‘Guide‘;    // 如果要調試,最後的== ‘1‘改成‘2‘就好了    if (!window.localStorage || !options || !$.isArray(options) || localStorage[urlRoot] == ‘2‘) {        return;    }    var elGuideOverlay = $(‘#guideOverlay‘);    var elGuideShut = $(‘#guideShut‘);    var elGuide = $(‘#guideOverlap‘);    var start = 0;    var remove = function () {        elGuideOverlay.remove();        elGuideShut.remove();        elGuide.remove();        // 鍵盤事件移除        $(document).off(‘keydown.guide‘);        $(window).off(‘resize.guide‘);    };    var goto = function (change) {        start = start + change;        if (start < 0) {            start = 0;        }        if (!options[start]) {            remove();            return;        }        var data = $.extend({}, defaults, options[start]);                //回調的時候才開啟遮罩        $(‘#guideOverlap‘).css({boxShadow: ‘0 0 0 9999px rgba(0,0,0,.75)‘});        // 擷取元素        var elTrigger = $(data.selector).eq(0);        if (elTrigger.length == 0 && change && data.selector!=‘‘) {            goto(change);            return;        }        // 裝載對應提示內容        elGuide.empty();        var elGuideContent = $(‘<div></div>‘).css({            //display: ‘none‘,            position: ‘absolute‘,        }).append(data.content);        elGuide.append(elGuideContent);        // 定位                if(elTrigger.length > 0){            elGuide.css({                width:elTrigger.outerWidth(),                height: elTrigger.outerHeight(),                left: elTrigger.offset().left || ‘0%‘,                top: elTrigger.offset().top || ‘50%‘            });        }else{            elGuide.css({                width:0,                height:0,                left: ‘0%‘,                top: ‘35%‘            });        }        // 提示內容定位        elGuideContent.css({            top: elTrigger.outerHeight() - 5 + data.offset.y        });        if (data.align == ‘left‘) {            elGuideContent.css({                left: data.offset.x            });        } else if (data.align == ‘right‘) {            elGuideContent.css({                right: data.offset.x            });        } else {            elGuideContent.css({                left: (elTrigger.outerWidth() - elGuideContent.width()) / 2 + data.offset.x            });        }                setTimeout(function () {            elGuideContent.show();        }, history.pushState? 100: 0);            };    if (!elGuideOverlay.length) {        elGuideOverlay = $(‘<a id="guideOverlay" href="javascript:" role="button"></a>‘).css({            position: ‘fixed‘,            left: 0,            top: 0,            right: 0,            bottom: 0,            background: ‘url(about:blank)‘,            zIndex: 99,            outline: ‘none‘        });                if (history.pushState) {            elGuideOverlay.css(‘background‘, ‘linear-gradient(to top, transparent, transparent)‘);            }        elGuideShut = $(‘<a href="javascript:" id="guideShut" role="button">跳過</a>‘).css({            position: ‘fixed‘,            top: 10,            right: 10,            color: ‘#fff‘,            zIndex: 10000        });;        elGuide = $(‘<div id="guideOverlap"></div>‘).css({            position: ‘absolute‘,            transition: ‘all .3s‘,            //boxShadow: ‘0 0 0 9999px rgba(0,0,0,.75)‘,            // 如果想支援圓角,下面的注釋            // borderRadius: ‘50%‘,            zIndex: 10000,        });                if (![].map) {            // IE8瀏覽器            elGuide.css(‘outline‘, ‘9999px solid #000‘).css(‘filter‘, ‘alpha(opacity=75)‘);        }                $(document.body).append(elGuideOverlay).append(elGuide).append(elGuideShut);        // 事件        elGuideShut.on(‘click‘, function () {            remove();        });        // 翻頁        elGuide.on({            click: function () {                //關閉遮罩                $(‘#guideOverlap‘).css({boxShadow: ‘none‘});                $(‘#guideOverlap‘).html(‘‘);                if(options[start]){                    options[start].clickFunc();                }                                if(options[start+1]){                    options[start+1].beforeFunc(function(){                        goto(1);                    });                }else{console.log(‘======‘+options[start+1]);                    goto(1);                }            }        });        // $(document).on(‘keydown.guide‘, function (event) {        //     var keycode = {        //         37: ‘left‘,        //         38: ‘up‘,        //         39: ‘right‘,        //         40: ‘down‘,        //         27: ‘esc‘        //     };        //     switch (keycode[event.keyCode]) {        //         case ‘esc‘: {        //             remove();        //             break;        //         }        //         case ‘up‘: case ‘left‘: {        //             goto(-1);        //             event.preventDefault();        //             break;        //         }        //         case ‘right‘: case ‘down‘: {        //             goto(1);        //             event.preventDefault();        //             break;        //         }        //     }        // });                $(window).on(‘resize.guide‘, function () {            //goto(0);        });    }    options[0].beforeFunc(function(){        goto(0);    });            //elGuideOverlay[0].focus();    localStorage[urlRoot] = ‘1‘;};

使用案例

 $.guide([{      beforeFunc:e,//執行前觸發,必須是一個帶回調的函數      clickFunc:e,//執行時觸發,必須是一個待回調的函數      selector: ‘‘,      content: ‘<img src="http://a326.sdsfshop.com/addons/ewei_shop/static/images/xinshou/1.png" style="width: 30rem;">‘,      align: ‘left‘ },{      beforeFunc:e,      clickFunc:e,      selector: ‘‘,      content: ‘<img src="http://a326.sdsfshop.com/addons/ewei_shop/static/images/xinshou/2.png" style="width: 30rem;">‘,      align: ‘left‘}])

function e(callback){
  if(callback){
    callback();
  }
}


 

function func1(callback){
  $(‘#wrapper‘).before(‘<div class="zhidao"></div>‘);
  $(‘.zhidao‘).animate({‘height‘:‘12%‘},{
    duration:3000,
    step:function(){
    },
    complete:function(){
    if(callback){
      callback();
    }
  }
  });
}

 

 

新手指導外掛程式.配合jquery使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.