mikegame 2014-07-09 04:07 采纳率: 0%
浏览 1061

菜鸟请高手帮忙看看两个JS文件为什么会冲突

文件一:
var ddsmoothmenu={

//Specify full URL to down and right arrow images (23 is padding-right added to top level LIs with drop downs):
arrowimages: {down:['downarrowclass', 'images/down.gif', 10], right:['rightarrowclass', 'images/right.gif']},
transition: {overtime:300, outtime:300}, //duration of slide in/ out animation, in milliseconds
shadow: {enable:true, offsetx:4, offsety:5}, //enable shadow?
showhidedelay: {showdelay: 100, hidedelay: 200}, //set delay in milliseconds before sub menus appear and disappear, respectively

///////Stop configuring beyond here///////////////////////////

detectwebkit: navigator.userAgent.toLowerCase().indexOf("applewebkit")!=-1, //detect WebKit browsers (Safari, Chrome etc)
detectie6: document.all && !window.XMLHttpRequest,

getajaxmenu:function($, setting){ //function to fetch external page containing the panel DIVs
var $menucontainer=$('#'+setting.contentsource[0]) //reference empty div on page that will hold menu
$menucontainer.html("Loading Menu...")
$.ajax({
url: setting.contentsource[1], //path to external menu file
async: true,
error:function(ajaxrequest){
$menucontainer.html('Error fetching content. Server Response: '+ajaxrequest.responseText)
},
success:function(content){
$menucontainer.html(content)
ddsmoothmenu.buildmenu($, setting)
}
})
},

buildmenu:function($, setting){
var smoothmenu=ddsmoothmenu
var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu UL
$mainmenu.parent().get(0).className=setting.classname || "ddsmoothmenu"
var $headers=$mainmenu.find("ul").parent()
$headers.hover(
function(e){
$(this).children('a:eq(0)').addClass('selected')
},
function(e){
$(this).children('a:eq(0)').removeClass('selected')
}
)
$headers.each(function(i){ //loop through each LI header
var $curobj=$(this).css({zIndex: 100-i}) //reference current LI header
var $subul=$(this).find('ul:eq(0)').css({display:'block'})
$subul.data('timers', {})
this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
this.istopheader=$curobj.parents("ul").length==1? true : false //is top level header?
$subul.css({top:this.istopheader && setting.orientation!='v'? this._dimensions.h+"px" : 0})
$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: smoothmenu.arrowimages.down[2]} : {}).append( //add arrow images
''
)
if (smoothmenu.shadow.enable){
this._shadowoffset={x:(this.istopheader?$subul.offset().left+smoothmenu.shadow.offsetx : this._dimensions.w), y:(this.istopheader? $subul.offset().top+smoothmenu.shadow.offsety : $curobj.position().top)} //store this shadow's offsets
if (this.istopheader)
$parentshadow=$(document.body)
else{
var $parentLi=$curobj.parents("li:eq(0)")
$parentshadow=$parentLi.get(0).$shadow
}
this.$shadow=$('

').prependTo($parentshadow).css({left:this._shadowoffset.x+'px', top:this._shadowoffset.y+'px'}) //insert shadow DIV and set it to parent node for the next shadow div
}
$curobj.hover(
function(e){
var $targetul=$subul //reference UL to reveal
var header=$curobj.get(0) //reference header LI as DOM object
clearTimeout($targetul.data('timers').hidetimer)
$targetul.data('timers').showtimer=setTimeout(function(){
header._offsets={left:$curobj.offset().left, top:$curobj.offset().top}
var menuleft=header.istopheader && setting.orientation!='v'? 0 : header._dimensions.w
menuleft=(header._offsets.left+menuleft+header._dimensions.subulw>$(window).width())? (header.istopheader && setting.orientation!='v'? -header._dimensions.subulw+header._dimensions.w : -header._dimensions.w) : menuleft //calculate this sub menu's offsets from its parent
if ($targetul.queue().length<=1){ //if 1 or less queued animations
$targetul.css({left:menuleft+"px", width:header._dimensions.subulw+'px'}).animate({height:'show',opacity:'show'}, ddsmoothmenu.transition.overtime)
if (smoothmenu.shadow.enable){
var shadowleft=header.istopheader? $targetul.offset().left+ddsmoothmenu.shadow.offsetx : menuleft
var shadowtop=header.istopheader?$targetul.offset().top+smoothmenu.shadow.offsety : header._shadowoffset.y
if (!header.istopheader && ddsmoothmenu.detectwebkit){ //in WebKit browsers, restore shadow's opacity to full
header.$shadow.css({opacity:1})
}
header.$shadow.css({overflow:'', width:header._dimensions.subulw+'px', left:shadowleft+'px', top:shadowtop+'px'}).animate({height:header._dimensions.subulh+'px'}, ddsmoothmenu.transition.overtime)
}
}
}, ddsmoothmenu.showhidedelay.showdelay)
},
function(e){
var $targetul=$subul
var header=$curobj.get(0)
clearTimeout($targetul.data('timers').showtimer)
$targetul.data('timers').hidetimer=setTimeout(function(){
$targetul.animate({height:'hide', opacity:'hide'}, ddsmoothmenu.transition.outtime)
if (smoothmenu.shadow.enable){
if (ddsmoothmenu.detectwebkit){ //in WebKit browsers, set first child shadow's opacity to 0, as "overflow:hidden" doesn't work in them
header.$shadow.children('div:eq(0)').css({opacity:0})
}
header.$shadow.css({overflow:'hidden'}).animate({height:0}, ddsmoothmenu.transition.outtime)
}
}, ddsmoothmenu.showhidedelay.hidedelay)
}
) //end hover
}) //end $headers.each()
$mainmenu.find("ul").css({display:'none', visibility:'visible'})
},

init:function(setting){
if (typeof setting.customtheme=="object" && setting.customtheme.length==2){ //override default menu colors (default/hover) with custom set?
var mainmenuid='#'+setting.mainmenuid
var mainselector=(setting.orientation=="v")? mainmenuid : mainmenuid+', '+mainmenuid
document.write('\n&#39;<br> +mainselector+&#39; ul li a {background:&#39;+setting.customtheme[0]+&#39;;}\n&#39;<br> +mainmenuid+&#39; ul li a:hover {background:&#39;+setting.customtheme[1]+&#39;;}\n&#39;<br> +&#39;')
}
this.shadow.enable=(document.all && !window.XMLHttpRequest)? false : this.shadow.enable //in IE6, always disable shadow
jQuery(document).ready(function($){ //ajax menu?
if (typeof setting.contentsource=="object"){ //if external ajax menu
ddsmoothmenu.getajaxmenu($, setting)
}
else{ //else if markup menu
ddsmoothmenu.buildmenu($, setting)
}
})
}

} //end ddsmoothmenu variable

文件二:
try {
document.execCommand('BackgroundImageCache', false, true);
}catch(e){

}

(function($){

jQuery.fn.extend({

d_imagechange:function(setting){

    var config = $.extend({
        bg:true,                        // 是否背景色
        title:true,                     // 是否有标题
        desc:true,                      // 是否有描述
        btn:true,                       // 是否显示按钮
        repeat:'no-repeat',             // 重复规则 'no-repeat' 'repeat-x' 'repeat-y' 'repeat'

        bgColor:'#000',                 // 背景色
        bgOpacity:.5,                   // 背景透明度
        bgHeight:40,                    // 背景高

        titleSize:14,                   // 标题文字大小
        titleFont:'Verdana,宋体',     // 标题文本字体
        titleColor:'#FFF',              // 标题文本颜色
        titleTop:4,                     // 标题上边距
        titleLeft:4,                    // 标题左边距

        descSize:12,                    // 描述文字大小
        descFont:'Verdana,宋体',          // 描述文本字体
        descColor:'#FFF',               // 描述文本颜色
        descTop:2,                      // 描述上边距
        descLeft:4,                     // 描述左边距

        btnColor:'#FFF',                // 按钮颜色1 
        btnOpacity:.5,                  // 未选中按钮透明度
        btnFont:'Verdana',              // 按钮文本字体
        btnFontSize:12,                 // 按钮文字大小(注意:Chrome有默认最小字号的限制)
        btnFontColor:'#000',            // 按钮文本颜色
        btnText:true,                   // 是否显示文本
        btnWidth:15,                    // 按钮宽
        btnHeight:15,                   // 按钮高
        btnMargin:4,                    // 按钮间距
        btnTop:4,                       // 按钮上边距

        playTime:2000,                  // 轮换间隔时间,单位(毫秒)
        animateTime:500,                // 动画执行时间,单位(毫秒)
        animateStyle:'o',               // 动画效果:'o':渐显 'x':横向滚动 'y':纵向滚动 'show':原地收缩伸展 'show-x':横向收缩伸展 'show-y':纵向收缩伸展' none':无动画
        width:300,                      // 宽, 不设定则从DOM读取
        height:200                      // 高, 不设定则从DOM读取

    },setting);

    return $(this).each(function(){
        var _this = $(this);
        var _w = config.width || _this.width();         // 宽
        var _h = config.height || _this.height();       // 高
        var _n = config.data.length;                    // 数目
        var _i = 0;                                     // 当前显示的item序号

        _this.empty()
             .css('overflow','hidden')
             .width(_w)
             .height(_h);

        // 半透明背景
        if(config.bg){
        $('<div />').appendTo(_this)
                    .width(_w)
                    .height(config.bgHeight)
                    .css('background-color',config.bgColor)
                    .css('opacity',config.bgOpacity)
                    .css('position','absolute')
                    .css('marginTop',_h-config.bgHeight)
                    .css('zIndex',3);
        }

        // 文字区
        var _textArea = 
        $('<div />').appendTo(_this)
                    .width(_w)
                    .height(config.bgHeight)
                    .css('position','absolute')
                    .css('marginTop',_h-config.bgHeight)
                    .css('zIndex',6);
        // 按钮区
        var _btnArea = 
        $('<div />').appendTo(_this)
                    .width(config.data.length * (config.btnWidth + config.btnMargin))
                    .height(config.bgHeight)
                    .css('position','absolute')
                    .css('marginTop',_h-config.bgHeight)
                    .css('marginLeft',_w-(config.btnWidth+config.btnMargin)*_n)
                    .css('zIndex',9)
                    .css('display',config.btn?'block':'none');

        // 插入空div修正IE的绝对定位BUG
        $('<div />').appendTo(_this);

        // 图片区
        var _imgArea = 
        $('<div />').appendTo(_this)
                    .width('x,show-x'.indexOf(config.animateStyle)!=-1?_w*_n:_w)
                    .height('y,show-y'.indexOf(config.animateStyle)!=-1?_h*_n:_h);          

        // 初始化图片 文字 按钮
        $.each(config.data,function(i,n){
            $('<a />').append($("<img />")
                      .width(_w)
                      .height(_h)
                      .attr("src", n.src)
                      ).appendTo(_imgArea)
                      .width(_w)
                      .height(_h)
                      .attr('href',n.href?n.href:'')
                      .attr('target',n.target?n.target:'')
                      .css('display','block')
                      .css('background-image','url('+n.src+')')
                      .css('background-repeat',config.repeat)
                      .css('display','block')
                      .css('float','x,show-x'.indexOf(config.animateStyle)!=-1?'left':'');

            if(config.title){
            $('<b />').appendTo(_textArea)
                      .html(n.title?n.title:'')
                      .css('display',i==0?'block':'none')
                      .css('fontSize',config.titleSize)
                      .css('fontFamily',config.titleFont)
                      .css('color',config.titleColor)
                      .css('marginTop',config.titleTop)
                      .css('marginLeft',config.titleLeft);
            }

            if(config.desc){
            $('<p />').appendTo(_textArea)
                      .html(n.desc?n.desc:'')
                      .css('display',i==0?'block':'none')
                      .css('fontSize',config.descSize)
                      .css('fontFamily',config.descFont)
                      .css('color',config.descColor)
                      .css('marginTop',config.descTop)
                      .css('marginLeft',config.descLeft);
            }


            $('<a />').appendTo(_btnArea)
                      .width(config.btnWidth)
                      .height(config.btnHeight)
                      .html(config.btnText?i+1:'')
                      .css('fontSize',config.btnFontSize)
                      .css('fontFamily',config.btnFont)
                      .css('textAlign','center')
                      .css('display','block')
                      .css('float','left')
                      .css('overflow','hidden')
                      .css('marginTop',config.btnTop)
                      .css('marginRight',config.btnMargin)
                      .css('background-color',config.btnColor)
                      .css('opacity',i==0?1:config.btnOpacity)
                      .css('color',config.btnFontColor)
                      .css('cursor','pointer')

        });

        // 保存所有元素集合的引用,方便在事件中使用
        var _bs = _btnArea.children('a');
        var _ts = _textArea.children('b');
        var _ds = _textArea.children('p');
        var _is = _imgArea.children('a');

        // 针对不同的动画效果的附加设置, 主要是block的问题, 若在初始化时设置block:none会造成之后无block效果
        if('o,show,none'.indexOf(config.animateStyle)!=-1){
            _is.not(':first').hide();
            _is.css('position','absolute');
        }

        // 添加按钮事件
        _bs.click(function(){
            var ii = _bs.index(this);
            if(ii==_i){return;}

            _ts.eq(_i).css('display','none');
            _ts.eq(ii).css('display','block');
            _ds.eq(_i).css('display','none');
            _ds.eq(ii).css('display','block');
            _bs.eq(_i).css('opacity',config.bgOpacity);
            _bs.eq(ii).css('opacity',1)

            switch(config.animateStyle){
            case 'o' :
                _is.eq(_i).fadeOut(config.animateTime);
                _is.eq(ii).fadeIn(config.animateTime);
                break;
            case 'x' :
                _imgArea.animate({marginLeft:-ii*_w},config.animateTime);
                break;
            case 'y' :
                _imgArea.animate({marginTop:-ii*_h},config.animateTime);
                break;
            case 'show' :
            case 'show-x' :
            case 'show-y' :
                _is.eq(_i).hide(config.animateTime);
                _is.eq(ii).show(config.animateTime);
                break;              
            case 'none' :
                _is.eq(_i).hide();
                _is.eq(ii).show();
                break;              
            }
            _i = ii;
        });

        // 添加轮换任务
        var _play = setInterval(play,config.playTime);

        function play(){
            _bs.eq((_i+1)%_n).click()
        }       
        // 鼠标进入事件
        _this.mouseover(function(){
            clearInterval(_play);
        });

        // 鼠标离开事件
        _this.mouseout(function(){
            _play = setInterval(play,config.playTime);
        });
    });
}

});

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我这模型写的不对吗?为什么lingo解出来的下面影子价格这一溜少一个变量
    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波