Is it possible to convert the text.json file into a jQuery animation?

Looking to extract information from text.json and integrate it with my jquery.animation().

My goal is similar to the one demonstrated here. Instead of using "data" attributes like in that example, I want to parse the text based on the "ID" property as a key value for each button to display text within middleBubble. The only difference between my version and the example is that my bubble toggles, so the text should be displayed after the animation.

I'm struggling to translate this into code to incorporate it into my jquery.animation(); this concept is new to me. Can someone assist me in coding this so I can comprehend how it functions?

This is the HTML for my animation:

<section class='circle-animation'>
        <div class="container-fluid">
          <div class="row">
            <div class="hidden-xs hidden-sm">
              <div class="col-sm-6 col-sm-offset-3 col-sm-pull-1">
                <div id="middlepapir" class="jumbotron">
                  <div class="row">

                    <img id="placeholder" class="papir img-responsive" src="img/circle/11.png" alt="">
                    <div class="row">
                      <div id="all" class="move1 col-sm-4 col-xs-4 col-md-push-4"> 
                          <a href="#"><img class="position1 round" src="img/circle/off/home-all-icon-off.png"></a>
                      </div>
                    </div>
                    <div class="row">
                      <div id="cover" class="move2 col-sm-4 col-xs-4 col-md-push-1">
                          <a href="#"><img class="position2 round" src="img/circle/off/home-cover-icon-off.png"></a>
                      </div>
                    </div>
                    <div class="row">
                      <div id="design" class="move3 col-sm-4 col-xs-4 col-md-push-7">
                          <a href="#"><img class="position3 round" src="img/circle/off/home-design-icon-off.png"></a>
                      </div>
                    </div>
                    <div class="row">
                      <div id="diy" class="move4 col-sm-4 col-xs-4">
                          <a href="#"><img class="position4 round" src="img/circle/off/home-diy-icon-off.png"></a>
                      </div>
                    </div>
                    <div class="row">
                      <div id="marketing" class="move5 col-sm-4 col-xs-4 col-md-push-8">
                          <a href="#"><img class="position5 round" src="img/circle/off/home-marketing-icon-off.png"></a>
                      </div>
                    </div>
                    <div class="row">
                      <div id="other" class="move6 col-sm-4 col-xs-4 col-md-push-1">
                          <a href="#"><img class="position6 round" src="img/circle/off/home-other-icon-off.png"></a>
                      </div>
                    </div>
                    <div class="row">
                      <div id="special" class="move7 col-sm-4 col-xs-4 col-md-push-4">
                          <a href="#"><img class="position7 round" src="img/circle/off/home-special-icon-off.png"></a>
                      </div>
                    </div>
                    <div class="row">
                      <div id="vip" class="move8 col-sm-4 col-xs-4 col-md-push-7">
                          <a href="#"><img class="position8 round" src="img/circle/off/home-vip-icon-off.png"></a>
                      </div>
                    </div>
                  </div>
                </div>   
              </div>  
            </div>  
          </div>    
        </div>
      </section>

This is the CSS for the animation:

/**
 *
 * Position icons into circle (SO)
 * 
 */

/* -------Up------ */ 

.move1 {

}

.move2 {
  margin-top: -80px;
}

.move3 {
  margin-top: -140px;
}
/* --------------- */


/* ------Middle---- */

.move5 {
   margin-top: -140px;
}


/* ---------------- */


/* ------Down------ */

.move7 {
  margin-top: -80px;
}

.move8 {
  margin-top: -195px;
}

/* --------------- */

.round {
  width: 140px;
  height: 140px;
}

.jumbotron {
  display: inline-block;
  width: 700px;
  height: 600px;
}

.jumbotron img.img-responsive {
  width: 450px;
  position: absolute;
  margin-top: 120px;
  margin-left: 60px;
}

Jquery:

// jQuery script for are Circle div whit Scroll Reveal Script

$(document).ready(function(){
    /*==========================================
    SCROLL REVEL SCRIPTS
    =====================================================*/
    window.scrollReveal = new scrollReveal();
    /*==========================================
    WRITE  YOUR  SCRIPTS BELOW
    =====================================================*/
    $('.round').click(function(){
       $('.papir').animate({
        width: ['toggle', 'swing'],
        height: ['toggle', 'swing'],
       }); 
    });    

});

The text available in text.json that I aim to include in my html:

var a = {
    "all":{
        "id":"all",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "cover": {
        "id":"cover",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "diy": {
        "id":"diy",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "marketing": {
        "id": "marketing",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "other": {
        "id": "other",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "special": {
        "id": "special",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "vip": {
        "id": "vip",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "design": {
        "id": "design",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }
}

Answer №1

Give this a try:

var a = {
    "all":{
        "id":"all",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "cover": {
        "id":"cover",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "diy": {
        "id":"diy",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "marketing": {
        "id": "marketing",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "other": {
        "id": "other",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "special": {
        "id": "special",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "vip": {
        "id": "vip",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }, "design": {
        "id": "design",
        "data": {
            "datatext": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
        }
    }
}


    $('div[class^="move"]').on('mouseover',function(){
        var id = $(this).attr('id');
        alert(a[id].data.datatext)
        $('.main-view').text(a[id].data.datatext);//.main-view is the text body where you display it

    })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implement Angular backend API on Azure Cloud Platform

I successfully created a backend API that connects to SQL and is hosted on my Azure account. However, I am unsure of the steps needed to deploy this API on Azure and make it accessible so that I can connect my Angular app to its URL instead of using loca ...

Tips for resolving the issue of windows resizing due to off-screen elementsplacement:

During the development of a project, I wanted to incorporate an effect into my webpage. To achieve this, I positioned elements off the screen. However, upon running the code, the window resized with scrollbars, causing inconvenience for mobile users Below ...

Guide to excluding all subdependencies using webpack-node-externals

My current setup involves using webpack to bundle both server assets and client code by specifying the target property. While this configuration has been working well, I encountered an issue where webpack includes all modules from node_modules even for ser ...

Every time I rotate my div, its position changes and it never goes back to

Trying to create an eye test by rotating the letter "E" when a directional button is clicked. However, facing an issue where the "E" changes position after the initial click instead of staying in place. Here is a GIF showcasing the problem: https://i.stac ...

Using varied colors to style list items

Is there a way to apply three different colors to my list items? What is the best method for achieving this? This is what I have in my code: li { width: 33.333%; float: left; padding: 15px; list-style: none; } .light { background-color: #0 ...

What are the best practices for utilizing "async/await" and "promises" in Node.js to achieve synchronous execution?

I'm fairly new to the world of web development and still grappling with concepts like promises and async/await. Currently, I'm working on a project to create a job posting site, but I've hit a roadblock trying to get a specific piece of code ...

What is the rationale behind not passing $scope to a service in AngularJS, and is it considered bad practice?

Is it advisable not to pass $scope to a service for certain reasons? I understand that services are intended to be reusable singletons, and passing a (potentially) large object to the service could lead to maintenance issues. However, assuming there is so ...

Challenge encountered with AJAX request

Whenever I trigger an AJAX request to a JSP using a dropdown menu, it works perfectly fine. However, when I try to trigger the same request using a submit button, the content vanishes and the page refreshes. function najax() { $.ajax({ url:"te ...

If the header 1 contains a specific word in jQuery, then carry out an action

I have successfully used the contains() function before, but I've never incorporated it into an if-statement. The code below doesn't seem to be working as expected. Essentially, I want to check if H1 contains the word "true" and perform a certain ...

Prevent user scrolling when full-screen menu is activated

Currently, I am developing a full-screen menu for a website and facing an issue with disabling the user's ability to scroll when the menu is open. Despite searching online, I have not found a suitable solution. It would be greatly appreciated if someo ...

Importing ES module into Next.js leads to ERR_REQUIRE_ESM

Encountered this issue while attempting to integrate ky into a Next.js project: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /foo/node_modules/ky/index.js It seems that the cause of this problem is Webpack (or Babel) converting all import ...

Achieving perfect alignment of two elements using flexbox: centering one and aligning the other to the right

Can you help me with aligning two elements to the center and right edge using flex? I am trying to achieve a layout similar to the image. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CSS Styles .flex{ display: flex; justify-content: space-between; align-i ...

Ways to access the properties of an HTML element with JQuery

Can anyone tell me how to extract the value from a specific HTML element using JQuery? For example: <span id="45463_test"></span> (the proper tags need to be used for the code to work correctly) Specifically, I am looking to retrieve the va ...

Is there a way to apply a css class to all nested elements in Angular 6 using Ngx Bootstrap?

I've defined a CSS class as follows: .panel-mobile-navs > ul > li { width:100% } Within the HTML, I am utilizing Ngx-bootstrap for a series of tabs like this: <tabset class="panel-mobile-navs" > ... </tabset> My intention is to ...

Trouble updating Kendo DropDown in Internet Explorer

Having an issue with updating a Kendo DropDownList through a javascript function. It works fine in FireFox and Chrome, but not in Internet Explorer. @(Html.Kendo().DropDownList() .Name("myDDL") .HtmlAttributes(new { style = "width: 320px" }) . ...

Achieving a transparent background in WebGLRender: A guide

I've been experimenting with placing objects in front of CSS3DObjects using the THREE.NoBlending hack. However, in the latest revisions (tested on r65 and r66), I only see the black plane without the CSS3DObject. Here is a small example I created: in ...

A JavaScript object featuring a predefined value

I have a simple goal that I'm unsure about achieving. My objective is to create an object that will return a specific value if no property is specified. For example: console.log(obj) // Should output "123" console.log(obj.x) // Should output "ABC" ...

How do I assign a default value to an optional parameter in a derived class in Typescript?

One of my classes is called ClientBase: export class ClientBase { constructor(private uri: string, private httpClient: HttpClient) { } // Contains Various Methods } I have multiple subclasses that are derived from the ClientBase For instance: @I ...

Whenever the page is refreshed, the props in my application are dynamically updated thanks to the getStaticProps function I utilize

Currently, I am in the process of learning nextjs as a beginner. Through the utilization of the getStaticProps function, I have come to understand that data fetching occurs only once at build time and the values remain static thereafter. Despite this, I ...

Number input in JavaScript being disrupted by stray commas

On my webpage, there are elements that users can control. One of these is a text input field for numbers. When users enter digits like 9000, everything functions correctly. However, if they use comma notation such as 9,000, JavaScript doesn't recogniz ...