做了一个网页,里面有两个JS特效。对应的代码如下:
JS1:(function($) {
$.fn.lavaLamp = function(o) {
o = $.extend({
fx: "linear",
speed: 500,
click: function() {}
},
o || {});
return this.each(function() {
var b = $(this),
noop = function() {},
$back = $('<li class="back"><div class="left"></div></li>').appendTo(b),
$li = $("li", this),
curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
$li.not(".back").hover(function() {
move(this)
},
noop);
$(this).hover(noop,
function() {
move(curr)
});
$li.click(function(e) {
setCurr(this);
return o.click.apply(this, [e, this])
});
setCurr(curr);
function setCurr(a) {
$back.css({
"left": a.offsetLeft + "px",
"width": a.offsetWidth + "px"
});
curr = a
};
function move(a) {
$back.each(function() {
$.dequeue(this, "fx")
}).animate({
width: a.offsetWidth,
left: a.offsetLeft
},
o.speed, o.fx)
}
})
}
})(jQuery);
if ($("#1").get(0)) {
$(function() {
$("#1").lavaLamp({
fx: "backout",
speed: 700,
click: function(event, menuItem) {
return true;
}
});
});
}
}JS2:(function($) {
$.fn.capslide = function(options) {
var opts = $.extend({}, $.fn.capslide.defaults, options);
return this.each(function() {
$this = $(this);
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
if(!o.showcaption) $this.find('.ic_caption').css('display','none');
else $this.find('.ic_text').css('display','none');
var _img = $this.find('img:first');
var w = _img.css('width');
var h = _img.css('height');
//$('.ic_caption',$this).css({'color':o.caption_color,'background-color':o.caption_bgcolor,'bottom':'0px','width':w});
$('.overlay',$this).css('background-color',o.overlay_bgcolor).css('opacity',0.8);
$this.css({'width':w , 'height':h, 'border':o.border});
$this.hover(
function () {
if((navigator.appVersion).indexOf('MSIE 7.0') > 0){
$('.overlay',$(this)).fadeIn(500);
$(this).find("h3").slideDown(500).show();
$(this).find("p").slideDown(500).show();}
else
$('.overlay',$(this)).fadeIn(500);
$(this).find("h3").fadeIn(500).show();
$(this).find("p").fadeIn(500).show();
},
function () {
if((navigator.appVersion).indexOf('MSIE 7.0') > 0){
$('.overlay',$(this)).fadeOut(500);
$(this).find("h3").fadeOut(500);
$(this).find("p").fadeOut(500);}
else
$('.overlay',$(this)).fadeOut(500);
$(this).find("h3").slideUp(500).hide();
$(this).find("p").slideUp(500).hide();
}
);
});
};
$.fn.capslide.defaults = {
caption_color : 'white',
caption_bgcolor : 'black',
overlay_bgcolor : 'blue',
border : '1px solid #fff',
showcaption : true
};
})(jQuery);
现在是加上js1的代码,js2的效果就不会出现,请问各位大神该如何解决? 谢谢!!
JS1:(function($) {
$.fn.lavaLamp = function(o) {
o = $.extend({
fx: "linear",
speed: 500,
click: function() {}
},
o || {});
return this.each(function() {
var b = $(this),
noop = function() {},
$back = $('<li class="back"><div class="left"></div></li>').appendTo(b),
$li = $("li", this),
curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
$li.not(".back").hover(function() {
move(this)
},
noop);
$(this).hover(noop,
function() {
move(curr)
});
$li.click(function(e) {
setCurr(this);
return o.click.apply(this, [e, this])
});
setCurr(curr);
function setCurr(a) {
$back.css({
"left": a.offsetLeft + "px",
"width": a.offsetWidth + "px"
});
curr = a
};
function move(a) {
$back.each(function() {
$.dequeue(this, "fx")
}).animate({
width: a.offsetWidth,
left: a.offsetLeft
},
o.speed, o.fx)
}
})
}
})(jQuery);
if ($("#1").get(0)) {
$(function() {
$("#1").lavaLamp({
fx: "backout",
speed: 700,
click: function(event, menuItem) {
return true;
}
});
});
}
}JS2:(function($) {
$.fn.capslide = function(options) {
var opts = $.extend({}, $.fn.capslide.defaults, options);
return this.each(function() {
$this = $(this);
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
if(!o.showcaption) $this.find('.ic_caption').css('display','none');
else $this.find('.ic_text').css('display','none');
var _img = $this.find('img:first');
var w = _img.css('width');
var h = _img.css('height');
//$('.ic_caption',$this).css({'color':o.caption_color,'background-color':o.caption_bgcolor,'bottom':'0px','width':w});
$('.overlay',$this).css('background-color',o.overlay_bgcolor).css('opacity',0.8);
$this.css({'width':w , 'height':h, 'border':o.border});
$this.hover(
function () {
if((navigator.appVersion).indexOf('MSIE 7.0') > 0){
$('.overlay',$(this)).fadeIn(500);
$(this).find("h3").slideDown(500).show();
$(this).find("p").slideDown(500).show();}
else
$('.overlay',$(this)).fadeIn(500);
$(this).find("h3").fadeIn(500).show();
$(this).find("p").fadeIn(500).show();
},
function () {
if((navigator.appVersion).indexOf('MSIE 7.0') > 0){
$('.overlay',$(this)).fadeOut(500);
$(this).find("h3").fadeOut(500);
$(this).find("p").fadeOut(500);}
else
$('.overlay',$(this)).fadeOut(500);
$(this).find("h3").slideUp(500).hide();
$(this).find("p").slideUp(500).hide();
}
);
});
};
$.fn.capslide.defaults = {
caption_color : 'white',
caption_bgcolor : 'black',
overlay_bgcolor : 'blue',
border : '1px solid #fff',
showcaption : true
};
})(jQuery);
现在是加上js1的代码,js2的效果就不会出现,请问各位大神该如何解决? 谢谢!!
我不能上传文件,麻烦老大通过下面的地址下载吧,帮忙看看,谢谢!http://www.miaojingyun.com/ceshi.rar
$(function() {
$("#1").lavaLamp({
fx: "backout",
speed: 700,
click: function(event, menuItem) {
return true;
}
});
});
// } 这个花括号是多余的
}
老大,测试第二个效果你可以尝试删除wwwCommon-0713.js中的
(function($) {
$.fn.lavaLamp = function(o) {
o = $.extend({
fx: "linear",
speed: 500,
click: function() {}
},
o || {});
return this.each(function() {
var b = $(this),
noop = function() {},
$back = $('<li class="back"><div class="left"></div></li>').appendTo(b),
$li = $("li", this),
curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
$li.not(".back").hover(function() {
move(this)
},
noop);
$(this).hover(noop,
function() {
move(curr)
});
$li.click(function(e) {
setCurr(this);
return o.click.apply(this, [e, this])
});
setCurr(curr);
function setCurr(a) {
$back.css({
"left": a.offsetLeft + "px",
"width": a.offsetWidth + "px"
});
curr = a
};
function move(a) {
$back.each(function() {
$.dequeue(this, "fx")
}).animate({
width: a.offsetWidth,
left: a.offsetLeft
},
o.speed, o.fx)
}
})
}
})(jQuery);
if ($("#1").get(0)) {
$(function() {
$("#1").lavaLamp({
fx: "backout",
speed: 700,
click: function(event, menuItem) {
return true;
}
});
});
}
}