[英]Multiple javascript functions in one file
I used some bootstrap javascript functions and one swiper function in one file.我在一个文件中使用了一些 bootstrap javascript 函数和一个 swiper 函数。 Problem is the swiper function doesnt work if i put it last in the code.
问题是如果我把它放在代码的最后,swiper 功能就不起作用。 If I put it first it works fine but the other functions stop working.
如果我把它放在第一位,它工作正常,但其他功能停止工作。 How to seperate them correctly so that each function is loaded fine.
如何正确地将它们分开,以便每个函数都能正常加载。
/* SIDEBAR */
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
/* SIDEBAR COLLAPSE */
$('.collapse').collapse()
$('.collapse-up').on('click',function(){
$('.collapse').collapse('hide');
});
/* ON/OFF BUTTON */
$("[name='checkbox']").bootstrapSwitch();
/* LOGIN MODAL*/
$('#login').modal(options) ;
/* RATING SLIDER */
$('#rate').slider({
formatter: function(value) {
tooltip: 'always'
return value + ' % ';
}
});
/* SWIPER */
var swiper = new Swiper('.keyword-swiper', {
slidesPerView: 2,
scrollbarHide: true,
grabCursor: true,
paginationClickable: true,
spaceBetween: 0,
freeMode: true,
});
<!--scrollbar: '.swiper-scrollbar',-->
is not valid JavaScript. <!--scrollbar: '.swiper-scrollbar',-->
不是有效的 JavaScript。 You need to use the /* */
comment style:您需要使用
/* */
注释样式:
var swiper = new Swiper('.keyword-swiper', {
/* scrollbar: '.swiper-scrollbar', */
slidesPerView: 2,
...
Or the //
comment style:或者
//
注释样式:
var swiper = new Swiper('.keyword-swiper', {
// scrollbar: '.swiper-scrollbar',
slidesPerView: 2,
...
The JavaScript interpreter tries to interpret <!-- -->
(an HTML comment) as JS code. JavaScript 解释器尝试将
<!-- -->
(HTML 注释)解释为 JS 代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.