我正在使用WordPress构建一个网站,无法让我的JavaScript工作。
我试图产生类似的效果:Click here 当你点击顾问的盒子时,会弹出一个图像和生物。
我制作了JavaScript并将其全部链接起来 - 但该框不会加载。
*/
$(document).ready(function() {
/*
*/
$('.classes a').click(function(e) {
e.preventDefault();
// Get the dimensions of the user's screen
var maskHeight = $(document).height();
var maskWidth = $(window).width();
// Set the mask overlay to fill the entire screen
$('.mask').css({'width':maskWidth,'height':maskHeight});
// Fade in the mask overlay
$('.mask').fadeTo(600, 0.7);
// Get the dimensions of the user's browser
var winHeight = $(window).height();
var winWidth = $(window).width();
// Set the bio pop-up to be in the middle of the screen
$('.classes-bio').css('top', winHeight/2-$('.classes-bio').height()/2);
$('.classes-bio').css('left', winWidth/2-$('.classes-bio').width()/2);
// Fade in the bio pop-up
$(this).parent('.classes').find('.classes-bio').delay(610).fadeIn(600);
});
// Click the mask or close button to fade out the pop-up and the mask
$('.mask, img.close-button').click(function(e) {
$('.classes-bio, .video-box').fadeOut(600);
$('.mask').delay(610).fadeOut(600);
});
/*
CSS:
.classes {
margin-bottom: 75px;
}
.classes {
width: 450px;
float: left;
margin: 10px 8px 0 0;
}
.classes:nth-child(4n+4) {
margin-right: 0;
}
.classes a {
text-decoration: none;
}
.classes h2,
.classes .classes-bio h2 {
font-weight: 700;
font-size: 1.5em;
text-transform: none;
margin: 15px 0 5px 12px;
}
.classes .classes-bio p {
color: #666;
line-height: 21px;
margin: 0 70px 18px 70px;
}
.classes .classes-bio p strong {
font-weight: 700;
}
.classes a.read-more {
color: #D1883E;
display: block;
margin: 12px 0 0 0px;
}
.classes a.read-more:hover {
text-decoration: underline;
}
.classes .classes-bio {
position: fixed;
width: 600px;
height: 90%;
display: none;
z-index: 9998;
padding-bottom: 10px;
background-color: #eaeaea;
}
.classes .classes-bio .close-button {
position: absolute;
top: -17px;
right: -17px;
z-index: 9999;
cursor: pointer;
}
.classes .classes-bio img.profile {
width: 238px;
margin: 25px 181px 8px;
}
.classes .classes-bio h2 {
text-align: center;
margin-bottom: 6px;
}
.classes .classes-bio p.job-title {
font-size: 1.1em;
margin-bottom: 28px;
}
.classes .classes-bio p {
font-size: 0.9em;
color: #000;
text-align: center;
}
/*
.mask {
position: absolute;
left: 0;
top: 0;
display: none;
z-index: 9997;
background-color: #000;
}
答案 0 :(得分:1)
看一下您提供的JavaScript代码,我可以立即看到* /
的第一行阻止JavaScript正常执行。同时删除/ *
尝试修复该页面上的所有代码错误。我进行了扫描,发现您的网页有35个错误http://validator.w3.org/check?uri=http://www.scpolechamps.co.uk/classes-2/
信不信由你,标记中最简单的错误可能会阻止JavaScript正常工作。
例如,在该页面上,您有以下内容:
<img style="border: 5px solid black;" "padding-bottom:10px;" alt="" src="/wp-content/themes/tigertone/images/pole.png" width="447" height="193" />
应该是:
<img src="/wp-content/themes/tigertone/images/pole.png" height="193" width="447" style="border:5px solid black;padding-bottom:10px" alt="Pole Dancing">
你有style="border: 5px solid black;" "padding-bottom:10px;"
,它应该像style="border:5px solid black;padding-bottom:10px"
添加时,应避免使用内联CSS。要为图像提供某种样式,请将CSS代码放在外部CSS文件中,并使用与您的图像对应的相应CSS ID或CLASS名称。它会以多种方式使您和您的访客受益。