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 7906677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:04:49+00:00 2026-06-03T11:04:49+00:00

I have a standard template in an Html file like: <template name=cards> {{#each all_cards}}

  • 0

I have a standard template in an Html file like:

<template name="cards">
  {{#each all_cards}}
    {{> card_item}}
  {{/each}}
</template>
<template name="card_item">
  <div class="card" style="left:{{position.x}}px; top:{{position.y}}px">
    {{title}}
  </div>
</template>

I want to have the cards (css selector .card) become draggable with JQuery.
Now since Meteor automagically updates the DOM using the template, when and how do I know where to call .draggable() on what??

EDIT: This is so far my solution which makes pending movements on other client visible with a wobble animation (using CSS3):

Template.card_item.events = {
'mouseover .card': function (e) {
    var $target = $(e.target);
    var $cardContainer = $target.hasClass('card') ? $target : $target.parents('.card');     
    $cardContainer.draggable({containment: "parent", distance: 3});
},
'dragstart .card': function (e) {
    Session.set("dragging_id", e.target.id);
    $(e.target).addClass("drag");
    pos = $(e.target).position();
    Events.insert({type: "dragstart", id:e.target.id, left: pos.left, top: pos.top});       
},
'dragstop .card': function (e) {
    pos = $(e.target).position();
    Events.insert({type: "dragstop", id:e.target.id, left: pos.left, top: pos.top});        
    Cards.update(e.target.id, {$set: {left:pos.left, top:pos.top}});
    Session.set("dragging_id", null);
}
}

Events.find().observe({
added: function(event) {
    if (event.type == "dragstart" && !Session.equals("dragging_id", event.id)) {
        $("#"+event.id).draggable({disabled: true});
        $("#"+event.id).addClass("wobble");             
    }
    if (event.type == "dragstop" && !Session.equals("dragging_id", event.id)) {
        $("#"+event.id).animate({left: event.left, top: event.top}, 250);           
        Events.remove({id:this.id});  
        $("#"+event.id).draggable({disabled: false});
    }
}
});
  • 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-03T11:04:50+00:00Added an answer on June 3, 2026 at 11:04 am

    EDIT: This approach doesn’t seem to work in the latest versions of Meteor, e.g. v0.5.0. See my comment below.

    Looks like we’re working on similar things! I’ve got a working proof of concept for a simple Magic: The Gathering app. Here’s how I have dragging implemented at the moment:

    In a <head> section in one of your html files, include the jQuery UI script:

    <script src="jquery-ui-1.8.20.custom.min.js"></script>
    

    Then, in a js file, make sure elements become draggable on mouseover (note: this is sub-optimal on touchscreens since it requires two touches to drag… I’m looking for a better touchscreen solution):

    Template.card_item.events['mouseover .card, touchstart .card'] = function (e) {
        var $target = $(e.target);
        if (!$target.data('isDraggable')) {
          $target.data('isDraggable', true).draggable();
        }
    };
    

    And finally, handle the drag and dragstop events:

    var prevDraggedTime = 0
    
    Template.card_item.events['drag .card'] = function (e) {
        // get the cardId from e
        var now = new Date().getTime();
        var position;
    
        if (now - prevDraggedTime > 250) {
            position = $(e.target).position();
            Cards.update(cardId, {$set: {x: position.top, y: position.left}});
            prevDraggedTime = now;
        }
    }
    
    Template.card_item.events['dragstop .card'] = function (e) {
        // get the cardId from e
        var position = $(e.target).position();
        Cards.update(cardId, {$set: {x: position.top, y: position.left}});
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom editor template for DateTimeOffset: @model DateTimeOffset <div> @Html.LabelFor(m =>
I have a product template that looks like this: The html for it is:
I have a _form.html.erb partial that comes from the standard rails 3 template for
I have a standard active record model with an attributes that is required: class
With StringTemplate, what is the proper way to have a standard layout template such
I have always been religiously using SGI's Standard Template Library Programmer's Guide (STLPG) as
I have a question regarding a HTML template.. I have create a template function
I need help with e-mail templates. I have an html template with three embedded
I've purchased a HTML/CSS template to use for a Rails app. I have the
I have smth like this: f.collection_select with options I need to modify the standard

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.