综合技术

Object literal object builder error javascript

微信扫一扫,分享到朋友圈

Object literal object builder error javascript
0

I am trying to organize my code using the object literal pattern, but I am getting an error: Uncaught ReferenceError: backToTop is not defined

Any ideas why?

Here’s the code:

(function($){

  var Mk = {

    config: {},

    init: function(config) {
      backToTop();
      wow();
      progressBarAnimation();
      slabText();
    },

    backToTop: function() {
      $('body').append('
Back to Top
'); $(window).scroll(function () { if ($(this).scrollTop() != 0) { $('#toTop').fadeIn(); } else { $('#toTop').fadeOut(); } }); $('#toTop').click(function(){ $("html, body").animate({ scrollTop: 0 }, 600); return false; }); }, wow: function() { var wow = new WOW({ boxClass: 'wow', animateClass: 'animated', offset: 0, mobile: true, live: true }); wow.init(); }, progressBarAnimation: function() { $.each($('div.progress-bar'),function(){ $(this).css('width', $(this).attr('aria-valuetransitiongoal')+'%'); }); }, slabText:function() { $("h1.mklife").slabText({ "viewportBreakpoint":400 }); }, last:'' }; $(document).ready(Mk.init()); window.Mk = Mk; })(jQuery)
  • Edit: I had missed the actual function call parentheses on document ready: $(document).ready(Mk.init());

The functions backToTop
, wow
, progressBarAnimation
, slabText
are methods of the Mk object, to access them reference the Mk object

init: function(config) {
  Mk.backToTop();
  Mk.wow();
  Mk.progressBarAnimation();
  Mk.slabText();
},

or since init is also a method of the same object you can access the function with the this
keyword

init: function(config) {
  this.backToTop();
  this.wow();
  this.progressBarAnimation();
  this.slabText();
},
阅读原文...

Hello, buddy!

Shape Symfony2 and Doctrine2 - update of the foreign key in the assigned entities fails &lb...

上一篇

林璟骅谈智慧零售:腾讯不做零售只做工具箱

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Object literal object builder error javascript

长按储存图像,分享给朋友