javascript - 请教下这个JQ代码怎么用模板引擎template.js
PHP中文网
PHP中文网 2017-04-10 13:11:31
[JavaScript讨论组]

jquery.wookmark.js插件默认这样的(插件地址https://github.com/GBKS/Wookmark-jQuery)下面是 example-api 里面一个例子

    (function ($) {
      var handler = null,
          page = 1,
          isLoading = false,
          apiURL = 'http://www.wookmark.com/api/json/popular';

      // Prepare layout options.
      var options = {
        autoResize: true, // This will auto-update the layout when the browser window is resized.
        container: $('#tiles'), // Optional, used for some extra CSS styling
        offset: 2, // Optional, the distance between grid items
        itemWidth: 210 // Optional, the width of a grid item
      };

      /**
       * When scrolled all the way to the bottom, add more tiles.
       */
      function onScroll(event) {
        // Only check when we're not still waiting for data.
        if(!isLoading) {
          // Check if we're within 100 pixels of the bottom edge of the broser window.
          var closeToBottom = ($(window).scrollTop() + $(window).height() > $(document).height() - 100);
          if(closeToBottom) {
            loadData();
          }
        }
      };

      /**
       * Refreshes the layout.
       */
      function applyLayout() {
        options.container.imagesLoaded(function() {
          // Create a new layout handler when images have loaded.
          handler = $('#tiles li');
          handler.wookmark(options);
        });
      };

      /**
       * Loads data from the API.
       */
      function loadData() {
        isLoading = true;
        $('#loaderCircle').show();

        $.ajax({
          url: apiURL,
          dataType: 'jsonp',
          data: {page: page}, // Page parameter to make sure we load new data
          success: onLoadData
        });
      };

      /**
       * Receives data from the API, creates HTML for images and updates the layout
       */
      function onLoadData(data) {
        isLoading = false;
        $('#loaderCircle').hide();

        // Increment page index for future calls.
        page++;

        // Create HTML for the images.
        var html = '';
        var i=0, length=data.length, image;
        for(; i';

          // Image title.
          html += '

'+image.title+'

'; html += ''; } // Add image HTML to the page. $('#tiles').append(html); // Apply layout. applyLayout(); }; // Capture scroll event. $(document).bind('scroll', onScroll); // Load first data from the API. loadData(); })(jQuery);

上面那个HTML是直接写在JS里面,怎么用模板引擎template.js替换掉(https://github.com/aui/artTemplate)

      function onLoadData(data) {
        isLoading = false;
        $('#loaderCircle').hide();

        // Increment page index for future calls.
        page++;

        // Create HTML for the images.
        var html = '';
        var i=0, length=data.length, image;
        for(; i';

          // Image title.
          html += '

'+image.title+'

'; html += ''; } // Add image HTML to the page. $('#tiles').append(html); // Apply layout. applyLayout(); };
PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(1)
迷茫

还是混到js里 意义不大 应该把模板独立出来成hbs或者html

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号