Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:50:13+00:00 2026-06-16T01:50:13+00:00

I am trying to create a pinterest like effect, and set the positions of

  • 0

I am trying to create a pinterest like effect, and set the positions of the divs via wedding.reposition(). However, I think the outerHeight() function is not working as it returns 0px. I thought this was due to the image not being loaded yet, but I only call the wedding.reposition() after the relevant div has been loaded and appended into the DOM (append is synchronous?).

Interestingly, if I run the wedding.reposition a few seconds later via a setTimeout function, it works. Just wondering if anyone has a solution for this?

//repositions all the elements on the page
wedding.reposition = function() {
  var $post = $(".post");
    //sets col position classes
    for(var i = 0, len = $post.length; i < len; i++) {
      //starts from base 1 rather than base 0
      var colClass = "col" + (i % 4 + 1);
      $post.eq(i).addClass(colClass);

      //implies it is on the second or greater row
      if(i >= 4) {
        var $col = $("." + colClass);
        //gets row of the element in the current column
        var row = Math.floor(i / 4);
        var $prev = $col.eq(row - 1);  

        //determines the height of the current object
        console.log($prev.outerHeight());
        var currentObjectHeight = $prev.position().top + $prev.outerHeight() + 15;
        $col.eq(row).css("top", currentObjectHeight);
      }
    };
};



//PostsView corresponds to the overall view holding individual PostView 
wedding.views.PostsView = Backbone.View.extend({
  el: "#column-container",

  initialize: function(){
    _.bindAll(this);
    this.collection.on("reset", this.render);

    this.collection.fetch();
  },

  render: function(){

    this.collection.each(function(model) {
      this.initializePostView(model);
    }, this);
    wedding.reposition();

  },

  initializePostView: function(model) {
    var html = new wedding.views.PostView({model: model});
    this.$el.append(html.render().el);

  }

});


wedding.views.PostView = Backbone.View.extend({

  className: "post",
  template: "#post-template",

  initialize: function(options) {
    _.bindAll(this);
    this.template = _.template($(this.template).html());
  },

  render: function() {
    this.preload();
    return this;
  },

  preload: function() {
    var image = new Image(); 
    var that = this;
    image.src = this.model.get("src");

    image.onload = function() {
      var html = that.template( {model: that.model.toJSON() });
      that.$el.append(html);
    };
  }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:50:15+00:00Added an answer on June 16, 2026 at 1:50 am

    While you may be appending to the DOM, it doesn’t mean the image will be downloaded.

    Use the load event for the image, or a plugin such as waitForImages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create framework for vacancies listing in pinterest-like way (infinite 5-columns
I'm trying to create a pinterest pin it button. Below is the code: <a
Is there any way to create a dynamic Pinterest button? I'm trying to add
I trying create a class derivated from System.Web.UI.Page and in override Render i set
I'm trying create this function such that if any key besides any of the
I am trying to create a custom enumeration via a series of facts. greater(X,Y)
I'm trying to create a payment calculator, however I am encountering an error in
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.