執行this.setSettingValue()時出錯
報錯:carousel.js:34 Uncaught SyntaxError: Unexpected identifier
index.html:41 Uncaught ReferenceError: Carousel is not defined
代碼:
;(function($){
var Carousel=function(poster){
//保存單個旋轉木馬對象
this.poster=poster;
//默認配置參數
this.setting={
? ? ? ? "width":1000, ? ? ? ?//幻燈片的寬度
"height":270, ? ? ? ?//幻燈片的高度
"posterWidth":640, ? //幻燈片第一幀的寬度
"posterHeight":270, ?//幻燈片第一幀的高度
"scale":0.9,
"speed":500,
"verticalAlign":"middle"
? ? ? ? };
$.extend(this.setting,this.getSetting());
//設置配置參數值
this.setSettingValue();
}
Carousel.prototype={
//設置配置參數值去控制基本的寬度高度。。。
setSettingValue:function(){
this.poster.css({
width:this.setting.width,
height:this.setting.height
});
}
//獲取人工配置參數
getSetting:function(){
var setting=this.poster.attr("data-setting");
if(setting&&setting!=""){
return $.parseJSON(setting);
}else{
return {};
};
}
};
Carousel.init=function(posters){
var _this_=this;
posters.each(function(){
new _this_($(this)); ?
? ?});
};
window["Carousel"]=Carousel;
})(jQuery);
2017-08-07
沒有逗號,Carousel.prototype={}中是用對對象字面量的方法來添加方法的,所以每個方法之間要有逗號
2017-03-03
截圖,看得眼都花了