我試圖在用戶點擊導航菜單中的「聯繫人」時打開一個精美的框彈出窗口。它適用於JSFiddle,見http://jsfiddle.net/88X6D/1/,但由於某種原因,它不能在實時環境中工作,請參閱http://goo.gl/lkfxeO(點擊菜單中的「聯繫人」時沒有任何反應)Fancybox開放問題 - 適用於JSFiddle,但不適用於實時環境
我最初認爲「平滑滾動「腳本和」聯繫表單「腳本,但由於它在JSfiddle上工作,問題必須在其他地方。 (也fancybox JS文件和jquery被正確調用)。
感謝您的幫助
HTML
<li> <a href="#inline" class="modalbox highlightit">Contact</a>
</li>
腳本(位於本文件:JS/scripts.js中)
//==============
//! Smooth scrolling
//==============
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 100
}, 'normal');
return false;
}
}
});
})
window.onscroll = scrollFunction;
function scrollFunction() {
var doc = document.documentElement, body = document.body;
var top = (doc && doc.scrollTop || body && body.scrollTop || 0);
if (top > 200) {
$('.back-to-top').fadeIn();
}
else {
$('.back-to-top').fadeOut();
}
}
//==============
//! Contact form
//==============
function validateEmail(email) {
var reg = /^(([^<>()[\]\\.,;:\[email protected]\"]+(\.[^<>()[\]\\.,;:\[email protected]\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return reg.test(email);
}
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function(){
var emailval = $("#email").val();
var msgval = $("#msg").val();
var msglen = msgval.length;
var mailvalid = validateEmail(emailval);
var nameval = $("#name").val();
if(mailvalid == false) {
$("#email").addClass("error");
}
else if(mailvalid == true){
$("#email").removeClass("error");
}
if(msglen < 4) {
$("#msg").addClass("error");
}
else if(msglen >= 4){
$("#msg").removeClass("error");
}
if(nameval < 2) {
//name must be at least 2 characters
$("#name").addClass("error");
}
else if(nameval >= 2){
$("#name").removeClass("error");
}
if(mailvalid == true && msglen >= 4) {
// if both validate we attempt to send the e-mail
// first we hide the submit btn so the user doesnt click twice
$("#send").replaceWith("<em>sending...</em>");
$.ajax({
type: 'POST',
url: '../sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
$(this).before("<p><strong>Success! Your message has been sent, thank you.</strong></p>");
setTimeout("$.fancybox.close()", 1000);
});
}
}
});
}
});
});
你在哪裏調用'.fancybox()'和執行的fancybox設置(如[的fancybox文件]中描述(HTTP:/ /fancybox.net/howto))? –
感謝您的評論。我認爲你的鏈接是指舊版本的花式框。無論如何,我已經將此添加到我的標題 - 沒有成功: – Greg
原來你確實在源代碼中有這一行 - 它在'contact form'部分的'$(document).ready()調用中。請注意,您必須使用'.modalbox'而不是'.fancybox'作爲選擇器,因爲這是您的鏈接名稱。我認爲新的文檔是[在這裏](http://fancyapps.com/fancybox/#instructions)。 –