在我正在处理的网站上添加幻灯片后,一些使用 Jquery 的 Web 组件停止工作。然而,新添加的也使用 JQuery 的幻灯片按预期工作。
经过一些调试,我从下面的代码中确切地发现了 JQuery 的工作原理和不工作的地方。我在我的代码中添加了一条注释来表明这一点。
我在标题中导入我的 jquery 库,下面的代码是结束标记之前的最后一个代码<body>
。
<!--SLIDESHOW-->
$(document).ready(function() {
var options = {};
if (document.location.search) {
var array = document.location.search.split('=');
var param = array[0].replace('?', '');
var value = array[1];
if (param == 'animation') {
options.animation = value;
}
else if (param == 'type_navigation') {
if (value == 'dots_preview') {
$('.border_box').css({'marginBottom': '40px'});
options['dots'] = true;
options['preview'] = true;
}
else {
options[value] = true;
if (value == 'dots') $('.border_box').css({'marginBottom': '40px'});
}
}
}
$('.box_skitter_large').skitter(options);
// Highlight
$('pre.code').highlight({source:1, zebra:1, indent:'space', list:'ol'});
//**** everything above works, everything below this point does not! ****/
$(".expandButton").click(function(ev){
$(ev.target).closest(".company-container").find(".expand").css("height", "140px");
$(ev.target).closest(".company-container").find(".expand").toggle("fast");
});
$(".emailLink, .email-popup").click(function(e){
e.stopPropagation();
$(e.target).closest(".company-container").find(".expand").css("height", "140px");
$(e.target).closest(".company-container").find(".email-popup").show("fast");
$(e.target).closest(".company-container").find(".phone-popup").hide();
$(e.target).closest(".company-container").find(".address-popup").hide();
});
$(".addressLink, .address-popup").click(function(e){
e.stopPropagation();
$(e.target).closest(".company-container").find(".expand").css("height", "550px");
$(e.target).closest(".company-container").find(".address-popup").show("fast");
var address = $(e.target).closest(".company-container").find(".address").html(); //get address text
if(!($(e.target).closest(".company-container").find(".map").length)){ //check if it was loaded
$(e.target).closest(".company-container").find(".address-popup").html('<iframe class="map" style="margin-top:45px;" width="575" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q='+ address +' &aq=&ie=UTF8&hq=&hnear='+address+'&t=m&z=14&iwloc=A&output=embed"></iframe>');
}
$(e.target).closest(".company-container").find(".email-popup").hide();
$(e.target).closest(".company-container").find(".phone-popup").hide();
});
$(".phoneLink, .phone-popup").click(function(e){
e.stopPropagation();
$(e.target).closest(".company-container").find(".expand").css("height", "140px");
$(e.target).closest(".company-container").find(".phone-popup").show("fast");
$(e.target).closest(".company-container").find(".email-popup").hide();
$(e.target).closest(".company-container").find(".address-popup").hide();
});
$(document).click(function(e) {
if (!(e.target.class === "email-popup" || e.target.class === "phone-popup")) {
$(".email-popup, .phone-popup, .address-popup").hide("fast");
}
$(".expand").css("height","140px");
});
$(".tagKeyword").hover(function(){
$(this).css("background-color","#fff");
$(this).css("color","blue");
$(this).css("box-shadow","none");
});
$(".tagKeyword").mouseleave(function(){
$(this).css("background-color","#eee");
$(this).css("color","#556");
$(this).css("box-shadow","1px 1px 2px #ccc");
});
$(".search-container").hover(function(){
$(".search-container").css("background","url(./images/menu/menu-middle.png)");
});
$(".searchfield").Watermark("search");
});