Instructions for resizing an iframe and a div arranged next to each other in a layout similar to jsbin or jsfiddle

I am trying to resize a div and iframe using a toggler, but I am facing some challenges. I have experimented with different solutions such as and , but they are not working smoothly when one div is placed beside an iframe.

Even when placing the iframe inside a div, there seems to be some awkward behavior while resizing. I am looking for a functionality similar to http://jsbin.com or http://jsfiddle.net, where iframes can be resized perfectly.

I need a solution that only involves HTML, CSS/CSS3, JavaScript, JQuery, and JQuery UI. Any assistance in this matter would be greatly appreciated.

Answer №1

While this approach may not be the most efficient, it could serve as a preliminary solution. I have not conducted any extensive research on this topic and have relied solely on basic reasoning. One significant challenge I encountered was determining the mouse position over an iframe, which I attempted to solve by adjusting the z-index of both the iframe and an overlay div accordingly. Please note that this code has only been tested in Chrome and may not function properly across all browsers. It is advisable to copy and paste this code for local testing purposes, as it is divided into two separate files.

First File:

<!DOCTYPE html>
<html>
<head>
<style>
    #main_wrapper{
        position:relative;
        display:block;
        width:810px;
        height:800px;
    }
    #left_wrapper{
        background-color: yellow;       
        position:relative;
        float:left;
        width:400px;
        height:800px;
        padding:0px;
        margin:0px;
    }
    #right_wrapper{
        background-color: blue; 
        position:relative;
        float:right;
        width:400px;
        height:800px;
        padding:0px;
        margin:0px;
    }
    #middle_bar{
        background-color: black;        
        position:relative;
        float:left;
        width:10px;
        height:800px;
        margin:0px;
    }
    #middle_bar:hover{
        cursor:move;
    }
    #overlay_div{
        z-index: 1;
        background-color: rgba(10,10,10,.1);
        position:absolute;
        width:100%;
        height:100%;
    }
    #my_iframe{
        z-index: 2;
    }
</style>

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function(){
    starting_mouse_pos = 0; 
    mouse_down = false;

    $('#middle_bar').on('mousedown', function(event){                           
        starting_mouse_pos = event.pageX;
        mouse_down = true;      
        $('#overlay_div').css('z-index', '2');
        $('#my_iframe').css('z-index', '1');
    });
    $('#main_wrapper').on('mouseup', function(){
        mouse_down = false;
        $('#overlay_div').css('z-index', '1');
        $('#my_iframe').css('z-index', '2');
    });
    $('#main_wrapper').on('mousemove', function(event){     
        if(mouse_down){
            var ending_mouse_pos = event.pageX;             
            update_the_sizes(ending_mouse_pos);             
            starting_mouse_pos = ending_mouse_pos;
        }       
    });
    function update_the_sizes(ending_mouse_pos){
        var length_of_move = starting_mouse_pos - ending_mouse_pos;
        $('#left_wrapper').css('width', '-='+length_of_move);
        $('#right_wrapper').css('width', '+='+length_of_move);
        $('#my_iframe').css('width', '+='+length_of_move);      
    }   
}); 
</script>
</head>
<body>
<div id="main_wrapper">
    <div id="left_wrapper"></div>
    <div id="middle_bar"></div>
    <div id="right_wrapper">
        <div id="overlay_div"></div>
        <iframe id="my_iframe" width="400px" height="800px" src="myIframe.html" seamless></iframe>
    </div>
</div>
</body>
</html>

Second File (myIframe.html):

<!DOCTYPE html>
<html>
<head>
<style>
    #main_wrapper{
        position:relative;
        display:block;
        width:150px;
        height:150px;
        margin-left:auto;
        margin-right:auto;
        background-color: purple;
    }
    body{
        background-color: green;
    }

</style>

<script>

</script>
</head>
<body>
<div id="main_wrapper"> 
</div>
</body>
</html>

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

Utilizing a jQuery autocomplete feature to access an object

In the JSON data I am using, there are two main sections for GOD and LEG, each containing information about different ships. I want to extract all the ship names from both GOD and LEG categories and utilize them in a JQuery autocomplete feature. { "GOD" ...

Tips for optimizing search functionality in Angular to prevent loading all data at once

An exploration for information within vast datasets is triggered by AngularJS when the input contains more than 3 characters. var app = angular.module('test_table', []); app.controller('main_control',function($scope, $http){ $scope ...

instructions for selecting div id within the same "table td" element using jQuery

Here is the code snippet that I am working with: <td> <div id="div<%# Eval("Id") %>" class="Display"><%# Eval("Display") %></div> <div class="Actions"> </div> <div class="Comment"> <span>Comm ...

Displaying elements upon checkbox selection in React

Hello, I'm new to React and I am facing an issue with checkbox click handling in React. My goal is to display a div when a checkbox is checked and hide the div when the checkbox is unchecked. The current implementation only shows the div when the che ...

Diagram with Cascading Style Sheets and Hypertext Markup Language

As I work on creating a flowchart, here is the code that I have developed: #flowchart { width: 580px; text-align: center; font-family: sans-serif; font-size: .8em; margin: auto; } #flowchart a { ...

Steps for Sending Data Using a URL

I am having trouble deleting a row based on its id. Below is the code I am using: <tr> <th>ID</th> <th>Nom etudiant</th> <th>Prenom etudiant</th> ...

The results of running 'npm run dev' and 'npm run build prod' are different from each other

Currently, I am in the process of developing a progressive web app using Vue.js. During development, I utilize the command npm run dev to initiate the local server that serves the files over at http://localhost:8080/. When it comes time to build for produ ...

Guide to connecting an object's attribute with an Angular2 form element using select

Currently facing an issue with angular forms. I am attempting to set up a form that retrieves data from a mongo collection and presents it using the <select> directive. Utilizing a FormBuilder to set it up as shown below: ngOnInit() { this.addFo ...

Enhance the appearance of Google Maps by incorporating gradient effects, box shadows, or other similar visual

How can I add a linear gradient to Google Maps? Below is my code snippet. HTML <div id="map"></div> CSS #map{ height:100vh; background: linear-gradient(90deg, #f7f8fa 0%, rgba(247, 248, 250, 0) 18.73%), linear-gradient(180deg, # ...

Failure to prepare mySQLi statement due to multiple question marks being used in the form

Hello, I am currently working on implementing a multi field search feature. The form consists of four fields and the user has the flexibility to input information into one or more fields for querying the database. While the SQL query functions correctly i ...

What is the best way to handle when an input text element with a specific string in its ID is blurred?

Whenever a user exits any of the input text fields in a specific category (identified by ID), I need to update another input text field. Specifically, if any of the following input text fields: boxAmount1 boxAmount2 boxAmount3 boxAmount4 boxAmount5 ...ar ...

The uniform height of flex columns was spoiled by a child element with a display setting of flex

CSS: * { padding: 0; margin: 0; box-sizing: border-box; } body { display: flex; background-color: #F5F5F5; } body > header { display: flex; position: fixed; width: 100%; height: 60px; align-items: center; background-color: #373737 ...

What is the best way to extract the text inside a div element based on the input value in a

I attempted to extract the innerText of a div along with the input values within it. For instance: <div> My name is Shubham, I work for <input type="text"/> for the last 5 years.</div> My objective is to retrieve all the text ...

Using Jquery to Hide Elements based on their Name Attribute

Can anyone help me figure out how to hide a specific field based on its name attribute? For example: <input type="text" name="when_is_escrow_set_to_close" class=" regular-text" value="" /> I am familiar with using jQuery to hide elements based on t ...

I aim to arrange three div elements in a single row with varying widths - placing one on the left, another in the center, and the last

I am trying to have three div elements in one row with different widths - one on the left, one in the center and one on the right. The left div should be 160px The center div should be 640px The right div should be 160px My goal is for them to appear se ...

Using `new FormData(form)` to access form data without actually submitting the form

I'm facing an issue with my HTML form that has a file input. I need to handle the response from the form submission without refreshing the page. To achieve this, I've implemented an Ajax call to submit the form on my behalf. However, every time ...

Is there a way to retrieve all the default CSS properties of the input checkbox tag using JavaScript?

Despite attempting to use console.log with JavaScript, my efforts were unsuccessful. Here is an example: console.log(document.getElementsByTagName('input')[0].attributes[0]) ...

Divergent display of WordPress form input CSS between Firefox and Chrome

Trying to create an email opt-in box using Wordpress with a pre-installed theme. The box appears correctly in Firefox but is displaying incorrectly in Chrome. Issues include no padding in the text fields, different font colors, and extra padding above and ...

Issues with div misalignment during jQuery animation

I have successfully created an animation where a child div inside a parent div moves up by -60px when the mouse enters the parent div, and returns to its original position when the mouse leaves. However, I am facing an issue where if the mouse moves direct ...

Completing a form and saving data to a document

I have a form that successfully writes to a text file using PHP. However, after submitting the form, the page reloads and shows a blank page. Currently, there is a message that appears using jQuery after the form is submitted. My goal is to prevent the pa ...