Return an Attribute Value to an Object Javascript











up vote
-1
down vote

favorite












I`need to return the attribute value of "data-animate" and "data-speed" to the object fxBalloon. In that object those string values should be passed to duration : $speedFX and name :$nameFX but comes up undefined. Please look at code below and link for reference



https://codepen.io/paul-solomon/pen/MzjYmK?editors=1111.



<div class="container">
<div class="balloon">
<div class="fxballoon" data-animate="b_layer1" data-speed="6s">
<span>sample</span>
</div>
<div class="fxballoon" data-animate="b_layer2" data-speed="5s">
<span>sample</span>
</div>
<div class="fxballoon" data-animate="b_layer3" data-speed="3s">
<span>sample</span>
</div>
</div>
</div>

//Global Var
var $elemClass = $(".balloon .fxballoon");

var fxBalloon = {
elem : $elemClass,//Class or Id
name :$nameFX, //Sets Option Name for Balloon Animation
duration : $speedFX, //Sets Option for Speed
delay : "ease-in-out", //Sets Option for Easing
count : "infinite", // sets an Infinite Loop
action : "paused", // Sets the Play or Pause Action
$nameFX: function() {
dataAnimation();
},
$speedFX: function() {
dataSpeedAnimation();
},
$animationFX: function() {
$(this).each(function() { //Iterates over the object FxController
setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
});
}
};



fxBalloon.$animationFX();

// loops to get the data-speed attribute value from DOM
function dataSpeedAnimation(){
for( var i = 0; i < $elemClass.length;i++){
// console.log($elemClass[i].getAttribute("data-speed"));
$elemClass[i].getAttribute("data-speed");
}
}
// loops to get the data-animate attribute value from DOM
function dataAnimation(){
for( var i = 0; i < $elemClass.length;i++){
return $elemClass[i].getAttribute("data-animate");
}
}

// Object Construct for CSS to animate styles to DOM
function setAnimation(elem, name, duration, delay, count, action) {
$(elem).css({ "-webkit-animation": name + " "+ duration + " "+ delay + " "+ count });
$(elem).css({ "-moz-animation": name + " "+ duration + " "+ delay + " "+ count });
$(elem).css({ "-o-animation": name + " "+ duration + " "+ delay + " "+ count });
$(elem).css({ "animation": name + " "+ duration + " "+ delay + " "+ count});
$(elem).css({ "animation-play-state:": action});
}









share|improve this question




























    up vote
    -1
    down vote

    favorite












    I`need to return the attribute value of "data-animate" and "data-speed" to the object fxBalloon. In that object those string values should be passed to duration : $speedFX and name :$nameFX but comes up undefined. Please look at code below and link for reference



    https://codepen.io/paul-solomon/pen/MzjYmK?editors=1111.



    <div class="container">
    <div class="balloon">
    <div class="fxballoon" data-animate="b_layer1" data-speed="6s">
    <span>sample</span>
    </div>
    <div class="fxballoon" data-animate="b_layer2" data-speed="5s">
    <span>sample</span>
    </div>
    <div class="fxballoon" data-animate="b_layer3" data-speed="3s">
    <span>sample</span>
    </div>
    </div>
    </div>

    //Global Var
    var $elemClass = $(".balloon .fxballoon");

    var fxBalloon = {
    elem : $elemClass,//Class or Id
    name :$nameFX, //Sets Option Name for Balloon Animation
    duration : $speedFX, //Sets Option for Speed
    delay : "ease-in-out", //Sets Option for Easing
    count : "infinite", // sets an Infinite Loop
    action : "paused", // Sets the Play or Pause Action
    $nameFX: function() {
    dataAnimation();
    },
    $speedFX: function() {
    dataSpeedAnimation();
    },
    $animationFX: function() {
    $(this).each(function() { //Iterates over the object FxController
    setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
    });
    }
    };



    fxBalloon.$animationFX();

    // loops to get the data-speed attribute value from DOM
    function dataSpeedAnimation(){
    for( var i = 0; i < $elemClass.length;i++){
    // console.log($elemClass[i].getAttribute("data-speed"));
    $elemClass[i].getAttribute("data-speed");
    }
    }
    // loops to get the data-animate attribute value from DOM
    function dataAnimation(){
    for( var i = 0; i < $elemClass.length;i++){
    return $elemClass[i].getAttribute("data-animate");
    }
    }

    // Object Construct for CSS to animate styles to DOM
    function setAnimation(elem, name, duration, delay, count, action) {
    $(elem).css({ "-webkit-animation": name + " "+ duration + " "+ delay + " "+ count });
    $(elem).css({ "-moz-animation": name + " "+ duration + " "+ delay + " "+ count });
    $(elem).css({ "-o-animation": name + " "+ duration + " "+ delay + " "+ count });
    $(elem).css({ "animation": name + " "+ duration + " "+ delay + " "+ count});
    $(elem).css({ "animation-play-state:": action});
    }









    share|improve this question


























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I`need to return the attribute value of "data-animate" and "data-speed" to the object fxBalloon. In that object those string values should be passed to duration : $speedFX and name :$nameFX but comes up undefined. Please look at code below and link for reference



      https://codepen.io/paul-solomon/pen/MzjYmK?editors=1111.



      <div class="container">
      <div class="balloon">
      <div class="fxballoon" data-animate="b_layer1" data-speed="6s">
      <span>sample</span>
      </div>
      <div class="fxballoon" data-animate="b_layer2" data-speed="5s">
      <span>sample</span>
      </div>
      <div class="fxballoon" data-animate="b_layer3" data-speed="3s">
      <span>sample</span>
      </div>
      </div>
      </div>

      //Global Var
      var $elemClass = $(".balloon .fxballoon");

      var fxBalloon = {
      elem : $elemClass,//Class or Id
      name :$nameFX, //Sets Option Name for Balloon Animation
      duration : $speedFX, //Sets Option for Speed
      delay : "ease-in-out", //Sets Option for Easing
      count : "infinite", // sets an Infinite Loop
      action : "paused", // Sets the Play or Pause Action
      $nameFX: function() {
      dataAnimation();
      },
      $speedFX: function() {
      dataSpeedAnimation();
      },
      $animationFX: function() {
      $(this).each(function() { //Iterates over the object FxController
      setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
      });
      }
      };



      fxBalloon.$animationFX();

      // loops to get the data-speed attribute value from DOM
      function dataSpeedAnimation(){
      for( var i = 0; i < $elemClass.length;i++){
      // console.log($elemClass[i].getAttribute("data-speed"));
      $elemClass[i].getAttribute("data-speed");
      }
      }
      // loops to get the data-animate attribute value from DOM
      function dataAnimation(){
      for( var i = 0; i < $elemClass.length;i++){
      return $elemClass[i].getAttribute("data-animate");
      }
      }

      // Object Construct for CSS to animate styles to DOM
      function setAnimation(elem, name, duration, delay, count, action) {
      $(elem).css({ "-webkit-animation": name + " "+ duration + " "+ delay + " "+ count });
      $(elem).css({ "-moz-animation": name + " "+ duration + " "+ delay + " "+ count });
      $(elem).css({ "-o-animation": name + " "+ duration + " "+ delay + " "+ count });
      $(elem).css({ "animation": name + " "+ duration + " "+ delay + " "+ count});
      $(elem).css({ "animation-play-state:": action});
      }









      share|improve this question















      I`need to return the attribute value of "data-animate" and "data-speed" to the object fxBalloon. In that object those string values should be passed to duration : $speedFX and name :$nameFX but comes up undefined. Please look at code below and link for reference



      https://codepen.io/paul-solomon/pen/MzjYmK?editors=1111.



      <div class="container">
      <div class="balloon">
      <div class="fxballoon" data-animate="b_layer1" data-speed="6s">
      <span>sample</span>
      </div>
      <div class="fxballoon" data-animate="b_layer2" data-speed="5s">
      <span>sample</span>
      </div>
      <div class="fxballoon" data-animate="b_layer3" data-speed="3s">
      <span>sample</span>
      </div>
      </div>
      </div>

      //Global Var
      var $elemClass = $(".balloon .fxballoon");

      var fxBalloon = {
      elem : $elemClass,//Class or Id
      name :$nameFX, //Sets Option Name for Balloon Animation
      duration : $speedFX, //Sets Option for Speed
      delay : "ease-in-out", //Sets Option for Easing
      count : "infinite", // sets an Infinite Loop
      action : "paused", // Sets the Play or Pause Action
      $nameFX: function() {
      dataAnimation();
      },
      $speedFX: function() {
      dataSpeedAnimation();
      },
      $animationFX: function() {
      $(this).each(function() { //Iterates over the object FxController
      setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
      });
      }
      };



      fxBalloon.$animationFX();

      // loops to get the data-speed attribute value from DOM
      function dataSpeedAnimation(){
      for( var i = 0; i < $elemClass.length;i++){
      // console.log($elemClass[i].getAttribute("data-speed"));
      $elemClass[i].getAttribute("data-speed");
      }
      }
      // loops to get the data-animate attribute value from DOM
      function dataAnimation(){
      for( var i = 0; i < $elemClass.length;i++){
      return $elemClass[i].getAttribute("data-animate");
      }
      }

      // Object Construct for CSS to animate styles to DOM
      function setAnimation(elem, name, duration, delay, count, action) {
      $(elem).css({ "-webkit-animation": name + " "+ duration + " "+ delay + " "+ count });
      $(elem).css({ "-moz-animation": name + " "+ duration + " "+ delay + " "+ count });
      $(elem).css({ "-o-animation": name + " "+ duration + " "+ delay + " "+ count });
      $(elem).css({ "animation": name + " "+ duration + " "+ delay + " "+ count});
      $(elem).css({ "animation-play-state:": action});
      }






      javascript






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 6:49

























      asked Nov 12 at 6:48









      Paul Solomon

      34




      34
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          -1
          down vote













              var fxBalloon = {
          elem : $elemClass,//Class or Id
          name :"ease-in-out", //Sets Option Name for Balloon Animation
          duration : "ease-in-out", //Sets Option for Speed
          delay : "ease-in-out", //Sets Option for Easing
          count : "infinite", // sets an Infinite Loop
          action : "paused", // Sets the Play or Pause Action
          $nameFX:
          dataAnimation(),
          $speedFX:
          dataSpeedAnimation(),
          $animationFX: function() {

          $(this).each(function() { //Iterates over the object FxController
          dataSpeedAnimation();
          setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
          });
          }
          };
          fxBalloon.$animationFX();





          share|improve this answer





















          • Is there any way get the values of html attributes data-animate and data-animate and apply them to the name and duration values in the object fxballoon, I have a for loop function that iterates to get attributes. I want to be able to control the duration at different speeds (eg: 6s.5s,4s) pulling from the data-speed function. same with name value in the Object(eg:b_layer1,b_layer2, b_layer3).
            – Paul Solomon
            Nov 12 at 14:28












          • instead run a loop outside the object
            – Balaji V
            Nov 14 at 7:04










          • I already have the loop outside of the object. the Object comes back undefined when I call it in the object.
            – Paul Solomon
            Nov 14 at 16:27











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257120%2freturn-an-attribute-value-to-an-object-javascript%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          -1
          down vote













              var fxBalloon = {
          elem : $elemClass,//Class or Id
          name :"ease-in-out", //Sets Option Name for Balloon Animation
          duration : "ease-in-out", //Sets Option for Speed
          delay : "ease-in-out", //Sets Option for Easing
          count : "infinite", // sets an Infinite Loop
          action : "paused", // Sets the Play or Pause Action
          $nameFX:
          dataAnimation(),
          $speedFX:
          dataSpeedAnimation(),
          $animationFX: function() {

          $(this).each(function() { //Iterates over the object FxController
          dataSpeedAnimation();
          setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
          });
          }
          };
          fxBalloon.$animationFX();





          share|improve this answer





















          • Is there any way get the values of html attributes data-animate and data-animate and apply them to the name and duration values in the object fxballoon, I have a for loop function that iterates to get attributes. I want to be able to control the duration at different speeds (eg: 6s.5s,4s) pulling from the data-speed function. same with name value in the Object(eg:b_layer1,b_layer2, b_layer3).
            – Paul Solomon
            Nov 12 at 14:28












          • instead run a loop outside the object
            – Balaji V
            Nov 14 at 7:04










          • I already have the loop outside of the object. the Object comes back undefined when I call it in the object.
            – Paul Solomon
            Nov 14 at 16:27















          up vote
          -1
          down vote













              var fxBalloon = {
          elem : $elemClass,//Class or Id
          name :"ease-in-out", //Sets Option Name for Balloon Animation
          duration : "ease-in-out", //Sets Option for Speed
          delay : "ease-in-out", //Sets Option for Easing
          count : "infinite", // sets an Infinite Loop
          action : "paused", // Sets the Play or Pause Action
          $nameFX:
          dataAnimation(),
          $speedFX:
          dataSpeedAnimation(),
          $animationFX: function() {

          $(this).each(function() { //Iterates over the object FxController
          dataSpeedAnimation();
          setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
          });
          }
          };
          fxBalloon.$animationFX();





          share|improve this answer





















          • Is there any way get the values of html attributes data-animate and data-animate and apply them to the name and duration values in the object fxballoon, I have a for loop function that iterates to get attributes. I want to be able to control the duration at different speeds (eg: 6s.5s,4s) pulling from the data-speed function. same with name value in the Object(eg:b_layer1,b_layer2, b_layer3).
            – Paul Solomon
            Nov 12 at 14:28












          • instead run a loop outside the object
            – Balaji V
            Nov 14 at 7:04










          • I already have the loop outside of the object. the Object comes back undefined when I call it in the object.
            – Paul Solomon
            Nov 14 at 16:27













          up vote
          -1
          down vote










          up vote
          -1
          down vote









              var fxBalloon = {
          elem : $elemClass,//Class or Id
          name :"ease-in-out", //Sets Option Name for Balloon Animation
          duration : "ease-in-out", //Sets Option for Speed
          delay : "ease-in-out", //Sets Option for Easing
          count : "infinite", // sets an Infinite Loop
          action : "paused", // Sets the Play or Pause Action
          $nameFX:
          dataAnimation(),
          $speedFX:
          dataSpeedAnimation(),
          $animationFX: function() {

          $(this).each(function() { //Iterates over the object FxController
          dataSpeedAnimation();
          setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
          });
          }
          };
          fxBalloon.$animationFX();





          share|improve this answer












              var fxBalloon = {
          elem : $elemClass,//Class or Id
          name :"ease-in-out", //Sets Option Name for Balloon Animation
          duration : "ease-in-out", //Sets Option for Speed
          delay : "ease-in-out", //Sets Option for Easing
          count : "infinite", // sets an Infinite Loop
          action : "paused", // Sets the Play or Pause Action
          $nameFX:
          dataAnimation(),
          $speedFX:
          dataSpeedAnimation(),
          $animationFX: function() {

          $(this).each(function() { //Iterates over the object FxController
          dataSpeedAnimation();
          setAnimation(this.elem,this.name,this.duration,this.delay,this.count,this.action);
          });
          }
          };
          fxBalloon.$animationFX();






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 7:18









          Balaji V

          465




          465












          • Is there any way get the values of html attributes data-animate and data-animate and apply them to the name and duration values in the object fxballoon, I have a for loop function that iterates to get attributes. I want to be able to control the duration at different speeds (eg: 6s.5s,4s) pulling from the data-speed function. same with name value in the Object(eg:b_layer1,b_layer2, b_layer3).
            – Paul Solomon
            Nov 12 at 14:28












          • instead run a loop outside the object
            – Balaji V
            Nov 14 at 7:04










          • I already have the loop outside of the object. the Object comes back undefined when I call it in the object.
            – Paul Solomon
            Nov 14 at 16:27


















          • Is there any way get the values of html attributes data-animate and data-animate and apply them to the name and duration values in the object fxballoon, I have a for loop function that iterates to get attributes. I want to be able to control the duration at different speeds (eg: 6s.5s,4s) pulling from the data-speed function. same with name value in the Object(eg:b_layer1,b_layer2, b_layer3).
            – Paul Solomon
            Nov 12 at 14:28












          • instead run a loop outside the object
            – Balaji V
            Nov 14 at 7:04










          • I already have the loop outside of the object. the Object comes back undefined when I call it in the object.
            – Paul Solomon
            Nov 14 at 16:27
















          Is there any way get the values of html attributes data-animate and data-animate and apply them to the name and duration values in the object fxballoon, I have a for loop function that iterates to get attributes. I want to be able to control the duration at different speeds (eg: 6s.5s,4s) pulling from the data-speed function. same with name value in the Object(eg:b_layer1,b_layer2, b_layer3).
          – Paul Solomon
          Nov 12 at 14:28






          Is there any way get the values of html attributes data-animate and data-animate and apply them to the name and duration values in the object fxballoon, I have a for loop function that iterates to get attributes. I want to be able to control the duration at different speeds (eg: 6s.5s,4s) pulling from the data-speed function. same with name value in the Object(eg:b_layer1,b_layer2, b_layer3).
          – Paul Solomon
          Nov 12 at 14:28














          instead run a loop outside the object
          – Balaji V
          Nov 14 at 7:04




          instead run a loop outside the object
          – Balaji V
          Nov 14 at 7:04












          I already have the loop outside of the object. the Object comes back undefined when I call it in the object.
          – Paul Solomon
          Nov 14 at 16:27




          I already have the loop outside of the object. the Object comes back undefined when I call it in the object.
          – Paul Solomon
          Nov 14 at 16:27


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257120%2freturn-an-attribute-value-to-an-object-javascript%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)