[英]Javascript not loading in website
I have a button in my website which on clicking pops up the menu. 我的网站上有一个按钮,单击后会弹出菜单。 I have included the JS file properly, but it doesn't seem to work .
我已经正确包含了JS文件,但是它似乎不起作用。 Is there an error with the JS file or HTML.
JS文件或HTML是否存在错误。 Files are as follows .
文件如下。
mainfile.js mainfile.js
var $blob = $('<blob/>');
var $blob2 = $('<blob class="blob2"/>');
$('#sidebarToggle').on('click', function() {
$(this).closest('.menu').toggleClass('open');
$('.page').toggleClass('open');
});
$('.link').on('mouseleave touchend', function(e) {
//e.preventDefault();
$blob.css({
top: e.offsetY + 'px',
left: e.offsetX + 'px'
});
$blob.removeClass('scale');
});
$('.link').on('mousemove touchmove', function(e) {
e.preventDefault();
$(this).find('blob').css({
top: e.offsetY + 'px',
left: e.offsetX + 'px'
});
});
$('.sidebar').on('mousemove touchmove', function(e) {
e.preventDefault();
});
$('.link').on('mouseenter touchstart', function(e) {
$blob.css({
top: e.offsetY + 'px',
left: e.offsetX + 'px'
});
$(this).append($blob);
setTimeout(function() {
$blob.addClass('scale');
}, 20);
});
$('.link').on('click', function(e) {
e.preventDefault();
$blob2.css({
top: e.offsetY + 'px',
left: e.offsetX + 'px'
});
$blob2.removeClass('scale');
$(this).append($blob2);
setTimeout(function() {
$blob2.addClass('scale');
}, 20);
var target = $(this).attr('href');
var scroll = $(target)[0].offsetTop - 70;
$('html, body').animate({
scrollTop: scroll
});
});
HTML Button Element: HTML按钮元素:
<script src="js/mainfile.js"></script>
<div class="sidebar">
<div class="menu">
<div id="sidebarToggle" class="button"><span></span><span></span></div>
<ul class="morpher">
<li class="item"><a href="#" class="link"><span>Resume</span></a></li>
<li class="item"><a href="#about_me" class="link"><span>About Me</span></a></li>
<li class="item"><a href="#my_experience" class="link"><span>my experience</span></a></li>
<li class="item"><a href="#my_projects" class="link"><span>my projects</span></a></li>
<li class="item"><a href="#social" class="link"><span>social</span></a></li>
<li class="item"><a href="#contact" class="link"><span>contact</span></a></li>
</ul>
</div>
</div>
You should always use a fall-back method if you're going to use a CDN, in case the CDN is not available for the library. 如果要使用CDN,则应始终使用后备方法,以防CDN无法用于库。 That means downloading a copy of jQuery and storing it locally.
这意味着下载jQuery副本并将其存储在本地。 The you can use this code -
您可以使用此代码-
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='path/to/jquery-1.11.1.min.js'
type='text/javascript'%3E%3C/script%3E"));
}
</script>
At head tag of html add this line of code 在html的head标签处添加此行代码
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
this will add jQuery 这将添加jQuery
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.