简体   繁体   English

如何在不阻止功能的情况下编辑此Javascript?

[英]How can I edit this Javascript without blocking functionality?

So I inherited some code that I am trying to customize and I've hit a roadblock. 因此,我继承了一些我试图自定义的代码,但遇到了障碍。 I believe this little piece of code is the issue: 我相信这小段代码就是问题所在:

jQuery(function($){
var photos = [
'cover/001_final.jpg',
'cover/002_final.jpg',
'cover/003_final.jpg',
'cover/004_final.jpg',
'cover/006_final.jpg',
'cover/007_final.jpg',
'cover/008_final.jpg',
'cover/009_final.jpg',
'cover/044_final.jpg',
'cover/085_final.jpg',
'cover/123_final.jpg' ]

$.backstretch(photos[Math.floor(Math.random() * photos.length)]);

$(document.body).on("backstretch.show", function () {
$('body').addClass('load');
});

$('.nav-link a')
  .hover(
    function() { $(this).addClass('hover'); },
    function() { $(this).removeClass('hover'); })
  .click(function(){
    $(this).removeClass('hover');
  });
});

If I understand correctly, this script is randomly loading the backgrounds and then stretching the images and then loading the menu... 如果我理解正确,则此脚本将随机加载背景,然后拉伸图像,然后加载菜单...

..I would like to use the menu feature on another page that does not require a stretched background, how can I remove the dependency on the background loading/stretching and just load the menu? ..我想在不需要延伸背景的另一页上使用菜单功能,如何删除对背景加载/拉伸的依赖,而只加载菜单?

Thanks in advance. 提前致谢。

Try using : 尝试使用:

$(function () {
    $('body').addClass('load');
});

Instead of : 代替 :

$(document.body).on("backstretch.show", function () {
    $('body').addClass('load');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM